Refined search code and wired up the client side search with server
This commit is contained in:
parent
ecccebe7c5
commit
1688e7fffa
3 changed files with 94 additions and 55 deletions
|
|
@ -64,9 +64,28 @@ public class ServerUtils {
|
|||
return list; // JSON string-> List<Recipe> (Jackson)
|
||||
}
|
||||
|
||||
/**
|
||||
* The method used by the search bar to get filtered recipes.
|
||||
* @param filter - filter string
|
||||
* @param locales - locales of the user
|
||||
* @return filtered recipe list
|
||||
*/
|
||||
public List<Recipe> getRecipesFiltered(String filter, List<String> locales) throws IOException, InterruptedException {
|
||||
// TODO: implement filtering on server side
|
||||
return this.getRecipes(locales);
|
||||
//TODO add limit integration
|
||||
String uri = SERVER + "/recipes?search=" + filter + "&locales=" + String.join(",", locales);
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(uri))
|
||||
.GET()
|
||||
.build();
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if(response.statusCode() != statusOK){
|
||||
throw new IOException("Failed to get filtered recipes. Server responds with " + response.body());
|
||||
}
|
||||
|
||||
List<Recipe> list = objectMapper.readValue(response.body(), new TypeReference<List<Recipe>>() {});
|
||||
logger.info("Received filtered recipes from server: " + list);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue