Skip to content

Commit

Permalink
Fully implemented the expand parameter to all resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkomen committed Jul 22, 2018
1 parent dfee057 commit 7c9e81d
Show file tree
Hide file tree
Showing 21 changed files with 199 additions and 156 deletions.
25 changes: 14 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,90 +14,93 @@ environment such as Git Bash. Now you can start the application by typing the fo

You can now access the REST resources using your browser or any REST client such as Postman or curl from your command line.
E.g. navigating to http://localhost:8080/corpses should give you a list of corpses.

## Query parameters
For all resources the query parameter ?expand=true can be appended to get a full list of JSON objects at the collection resource level. For example, instead of http://localhost:8080/achievements the url http://localhost:8080/achievements?expand=true should be used.

## Achievements

A list of all achievements (200 KB):
A list of all achievements:
http://localhost:8080/achievements

An achievement by achievement name, e.g. "Goo Goo Dancer":
http://localhost:8080/achievements/Goo_Goo_Dancer

## Books

A list of all books (1.1 MB):
A list of all books:
http://localhost:8080/books

A book by book name, e.g. "Dungeon Survival Guide (Book)":
http://localhost:8080/books/Dungeon_Survival_Guide_%28Book%29

## Buildings

A list of all buildings (223 kB):
A list of all buildings:
http://localhost:8080/buildings

A building by building name, e.g. "Theater Avenue 8b":
http://localhost:8080/buildings/Theater_Avenue_8b

## Corpses

A list of all corpses (16 kB):
A list of all corpses:
http://localhost:8080/corpses

A corpse by corpse name, e.g. "Dead Rat":
http://localhost:8080/corpses/Dead_Rat

## Creatures

A list of all creatures (2.55 MB):
A list of all creatures:
http://localhost:8080/creatures

A creature by creature name, e.g. "Dragon":
http://localhost:8080/creatures/Dragon

## Effects

A list of all effects (31 kB):
A list of all effects:
http://localhost:8080/effects

An effect by effect name, e.g. "Throwing Cake Effect":
http://localhost:8080/effects/Throwing_Cake_Effect

## Locations (Geography)

A list of all locations (12 kB):
A list of all locations:
http://localhost:8080/locations

A location by location name, e.g. "Thais":
http://localhost:8080/locations/Thais

## Hunting Places (in progress)

A list of all hunting places (12 kB):
A list of all hunting places:
http://localhost:8080/huntingplaces

A location by location name, e.g. "Hero Cave":
http://localhost:8080/huntingplaces/Hero_Cave

## Keys

A list of all keys (62 kB):
A list of all keys:
http://localhost:8080/keys

A key by key name (not only the number but the full wiki pagename), e.g. "Key 4055":
http://localhost:8080/keys/Key_4055

## Mounts

A list of all mounts (43 kB):
A list of all mounts:
http://localhost:8080/mounts

A mount by mount name, e.g. "Donkey":
http://localhost:8080/mounts/Donkey

## NPCs

A list of all NPCs (706 kB):
A list of all NPCs:
http://localhost:8080/npcs

An NPC by NPC name, e.g. "Sam":
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/tibiawiki/process/RetrieveBooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public RetrieveBooks(ArticleRepository articleRepository, ArticleFactory article
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getBooksJSON() {
return getBooksJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getBooksJSON(boolean oneByOne) {
public List<String> getBooksList() {
final List<String> booksCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_BOOKS)) {
booksCategory.add(pageName);
Expand All @@ -38,13 +34,21 @@ public Stream<JSONObject> getBooksJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInBooksCategoryButNotLists = booksCategory.stream()
return booksCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getBooksJSON() {
return getBooksJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getBooksJSON(boolean oneByOne) {
final List<String> booksList = getBooksList();

return oneByOne
? obtainArticlesOneByOne(pagesInBooksCategoryButNotLists)
: obtainArticlesInBulk(pagesInBooksCategoryButNotLists);
? obtainArticlesOneByOne(booksList)
: obtainArticlesInBulk(booksList);
}

public Optional<JSONObject> getBookJSON(String pageName) {
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/tibiawiki/process/RetrieveBuildings.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public RetrieveBuildings(ArticleRepository articleRepository, ArticleFactory art
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getBuildingsJSON() {
return getBuildingsJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getBuildingsJSON(boolean oneByOne) {
public List<String> getBuildingsList() {
final List<String> buildingsCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_BUILDINGS)) {
buildingsCategory.add(pageName);
Expand All @@ -38,13 +34,21 @@ public Stream<JSONObject> getBuildingsJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInBuildingsCategoryButNotLists = buildingsCategory.stream()
return buildingsCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getBuildingsJSON() {
return getBuildingsJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getBuildingsJSON(boolean oneByOne) {
final List<String> buildingsList = getBuildingsList();

return oneByOne
? obtainArticlesOneByOne(pagesInBuildingsCategoryButNotLists)
: obtainArticlesInBulk(pagesInBuildingsCategoryButNotLists);
? obtainArticlesOneByOne(buildingsList)
: obtainArticlesInBulk(buildingsList);
}

public Optional<JSONObject> getBuildingJSON(String pageName) {
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/tibiawiki/process/RetrieveCorpses.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public RetrieveCorpses(ArticleRepository articleRepository, ArticleFactory artic
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getCorpsesJSON() {
return getCorpsesJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getCorpsesJSON(boolean oneByOne) {
public List<String> getCorpsesList() {
final List<String> corpsesCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_CORPSES)) {
corpsesCategory.add(pageName);
Expand All @@ -38,13 +34,21 @@ public Stream<JSONObject> getCorpsesJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInCorpsesCategoryButNotLists = corpsesCategory.stream()
return corpsesCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getCorpsesJSON() {
return getCorpsesJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getCorpsesJSON(boolean oneByOne) {
final List<String> corpsesList = getCorpsesList();

return oneByOne
? obtainArticlesOneByOne(pagesInCorpsesCategoryButNotLists)
: obtainArticlesInBulk(pagesInCorpsesCategoryButNotLists);
? obtainArticlesOneByOne(corpsesList)
: obtainArticlesInBulk(corpsesList);
}

public Optional<JSONObject> getCorpseJSON(String pageName) {
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/tibiawiki/process/RetrieveCreatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public RetrieveCreatures(ArticleRepository articleRepository, ArticleFactory art
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getCreaturesJSON() {
return getCreaturesJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getCreaturesJSON(boolean oneByOne) {
public List<String> getCreaturesList() {
final List<String> creaturesCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_CREATURES)) {
creaturesCategory.add(pageName);
Expand All @@ -38,13 +34,21 @@ public Stream<JSONObject> getCreaturesJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInCreaturesCategoryButNotLists = creaturesCategory.stream()
return creaturesCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getCreaturesJSON() {
return getCreaturesJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getCreaturesJSON(boolean oneByOne) {
final List<String> creaturesList = getCreaturesList();

return oneByOne
? obtainArticlesOneByOne(pagesInCreaturesCategoryButNotLists)
: obtainArticlesInBulk(pagesInCreaturesCategoryButNotLists);
? obtainArticlesOneByOne(creaturesList)
: obtainArticlesInBulk(creaturesList);
}

public Optional<JSONObject> getCreatureJson(String pageName) {
Expand Down
20 changes: 12 additions & 8 deletions src/main/java/com/tibiawiki/process/RetrieveEffects.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public RetrieveEffects(ArticleRepository articleRepository, ArticleFactory artic
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getEffectsJSON() {
return getEffectsJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getEffectsJSON(boolean oneByOne) {
public List<String> getEffectsList() {
final List<String> effectsCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_EFFECTS)) {
effectsCategory.add(pageName);
Expand All @@ -38,13 +34,21 @@ public Stream<JSONObject> getEffectsJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInEffectsCategoryButNotLists = effectsCategory.stream()
return effectsCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getEffectsJSON() {
return getEffectsJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getEffectsJSON(boolean oneByOne) {
final List<String> effectsList = getEffectsList();

return oneByOne
? obtainArticlesOneByOne(pagesInEffectsCategoryButNotLists)
: obtainArticlesInBulk(pagesInEffectsCategoryButNotLists);
? obtainArticlesOneByOne(effectsList)
: obtainArticlesInBulk(effectsList);
}

public Optional<JSONObject> getEffectJSON(String pageName) {
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/tibiawiki/process/RetrieveHuntingPlaces.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ public RetrieveHuntingPlaces(ArticleRepository articleRepository, ArticleFactory
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getHuntingPlacesJSON() {
return getHuntingPlacesJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getHuntingPlacesJSON(boolean oneByOne) {
public List<String> getHuntingPlacesList() {
final List<String> huntingPlacesCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_HUNTING_PLACES)) {
huntingPlacesCategory.add(pageName);
Expand All @@ -38,17 +34,24 @@ public Stream<JSONObject> getHuntingPlacesJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInHuntingPlacesCategoryButNotLists = huntingPlacesCategory.stream()
return huntingPlacesCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getHuntingPlacesJSON() {
return getHuntingPlacesJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getHuntingPlacesJSON(boolean oneByOne) {
final List<String> huntingPlacesList = getHuntingPlacesList();

return oneByOne
? obtainArticlesOneByOne(pagesInHuntingPlacesCategoryButNotLists)
: obtainArticlesInBulk(pagesInHuntingPlacesCategoryButNotLists);
? obtainArticlesOneByOne(huntingPlacesList)
: obtainArticlesInBulk(huntingPlacesList);
}

public Optional<JSONObject> getHuntingPlaceJSON(String pageName) {
return super.getArticleJSON(pageName);
}

}
23 changes: 17 additions & 6 deletions src/main/java/com/tibiawiki/process/RetrieveKeys.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.tibiawiki.process;

import com.tibiawiki.domain.factories.ArticleFactory;
import com.tibiawiki.domain.factories.JsonFactory;
import com.tibiawiki.domain.repositories.ArticleRepository;
import org.json.JSONObject;

import java.util.ArrayList;
Expand All @@ -16,11 +19,11 @@ public RetrieveKeys() {
super();
}

public Stream<JSONObject> getKeysJSON() {
return getKeysJSON(ONE_BY_ONE);
public RetrieveKeys(ArticleRepository articleRepository, ArticleFactory articleFactory, JsonFactory jsonFactory) {
super(articleRepository, articleFactory, jsonFactory);
}

public Stream<JSONObject> getKeysJSON(boolean oneByOne) {
public List<String> getKeysList() {
final List<String> keysCategory = new ArrayList<>();
for (String pageName : articleRepository.getMembersFromCategory(CATEGORY_KEYS)) {
keysCategory.add(pageName);
Expand All @@ -31,13 +34,21 @@ public Stream<JSONObject> getKeysJSON(boolean oneByOne) {
listsCategory.add(pageName);
}

final List<String> pagesInKeysCategoryButNotLists = keysCategory.stream()
return keysCategory.stream()
.filter(page -> !listsCategory.contains(page))
.collect(Collectors.toList());
}

public Stream<JSONObject> getKeysJSON() {
return getKeysJSON(ONE_BY_ONE);
}

public Stream<JSONObject> getKeysJSON(boolean oneByOne) {
final List<String> keysList = getKeysList();

return oneByOne
? obtainArticlesOneByOne(pagesInKeysCategoryButNotLists)
: obtainArticlesInBulk(pagesInKeysCategoryButNotLists);
? obtainArticlesOneByOne(keysList)
: obtainArticlesInBulk(keysList);
}

public Optional<JSONObject> getKeyJSON(String pageName) {
Expand Down

0 comments on commit 7c9e81d

Please sign in to comment.