Merge branch 'fix/search-bar-wiring' into 'main'

Refined search code and wired up the client side search with server

Closes #68

See merge request cse1105/2025-2026/teams/csep-team-76!66
This commit is contained in:
Zhongheng Liu 2026-01-18 18:30:48 +01:00
commit 75e9fc1e62
3 changed files with 94 additions and 55 deletions

View file

@ -56,9 +56,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;
}
/**