From 453e5b11bd706e5a2eafdfe48ce8df96bd5430ba Mon Sep 17 00:00:00 2001 From: Natalia Cholewa Date: Fri, 9 Jan 2026 23:49:10 +0100 Subject: [PATCH] fix: pipeline not passing --- .../java/client/scenes/FoodpalApplicationCtrl.java | 5 ++++- .../src/main/java/client/scenes/SearchBarCtrl.java | 7 +++++-- client/src/main/java/client/utils/ServerUtils.java | 14 ++++++-------- client/src/test/java/client/ServerUtilsTest.java | 4 ++-- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java index cdbd565..b36f3ed 100644 --- a/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java +++ b/client/src/main/java/client/scenes/FoodpalApplicationCtrl.java @@ -268,7 +268,10 @@ public class FoodpalApplicationCtrl implements LocaleAware { public void refresh() { List recipes; try { - recipes = server.getRecipesFiltered(searchBarController.getFilter()); + recipes = server.getRecipesFiltered( + searchBarController.getFilter(), + this.configService.getConfig().getRecipeLanguages() + ); } catch (IOException | InterruptedException e) { recipes = Collections.emptyList(); String msg = "Failed to load recipes: " + e.getMessage(); diff --git a/client/src/main/java/client/scenes/SearchBarCtrl.java b/client/src/main/java/client/scenes/SearchBarCtrl.java index 4f6113b..da40e3a 100644 --- a/client/src/main/java/client/scenes/SearchBarCtrl.java +++ b/client/src/main/java/client/scenes/SearchBarCtrl.java @@ -1,5 +1,6 @@ package client.scenes; +import client.utils.ConfigService; import client.utils.LocaleAware; import client.utils.LocaleManager; import client.utils.ServerUtils; @@ -28,6 +29,7 @@ public class SearchBarCtrl implements LocaleAware { private final LocaleManager localeManager; private final ServerUtils serverUtils; + private final ConfigService configService; private Consumer> onSearchCallback; @@ -41,9 +43,10 @@ public class SearchBarCtrl implements LocaleAware { private Task> currentSearchTask = null; @Inject - public SearchBarCtrl(LocaleManager localeManager, ServerUtils serverUtils) { + public SearchBarCtrl(LocaleManager localeManager, ServerUtils serverUtils, ConfigService configService) { this.localeManager = localeManager; this.serverUtils = serverUtils; + this.configService = configService; } @FXML @@ -96,7 +99,7 @@ public class SearchBarCtrl implements LocaleAware { currentSearchTask = new Task<>() { @Override protected List call() throws IOException, InterruptedException { - return serverUtils.getRecipesFiltered(filter); + return serverUtils.getRecipesFiltered(filter, configService.getConfig().getRecipeLanguages()); } }; diff --git a/client/src/main/java/client/utils/ServerUtils.java b/client/src/main/java/client/utils/ServerUtils.java index 8e48d6e..41d1236 100644 --- a/client/src/main/java/client/utils/ServerUtils.java +++ b/client/src/main/java/client/utils/ServerUtils.java @@ -29,11 +29,9 @@ public class ServerUtils { private final HttpClient client; private final ObjectMapper objectMapper = new ObjectMapper(); private final int statusOK = 200; - private final ConfigService configService; @Inject - public ServerUtils(ConfigService configService) { - this.configService = configService; + public ServerUtils() { client = HttpClient.newHttpClient(); } @@ -41,13 +39,13 @@ public class ServerUtils { * Gets all the recipes from the backend. * @return a JSON string with all the recipes */ - public List getRecipes() throws IOException, InterruptedException { + public List getRecipes(List locales) throws IOException, InterruptedException { String uri = SERVER + "/recipes" + "?locales=" + - String.join(",", this.configService.getConfig().getRecipeLanguages()); + String.join(",", locales); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(uri)) @@ -65,9 +63,9 @@ public class ServerUtils { return list; // JSON string-> List (Jackson) } - public List getRecipesFiltered(String filter) throws IOException, InterruptedException { + public List getRecipesFiltered(String filter, List locales) throws IOException, InterruptedException { // TODO: implement filtering on server side - return this.getRecipes(); + return this.getRecipes(locales); } /** @@ -96,7 +94,7 @@ public class ServerUtils { */ public Recipe addRecipe(Recipe newRecipe) throws IOException, InterruptedException { //Make sure the name of the newRecipe is unique - List allRecipes = getRecipes(); + List allRecipes = getRecipes(List.of()); newRecipe.setId(null); // otherwise the id is the same as the original, and that's wrong // now that each recipeIngredient has its own ID in the database, // we set that to null too to force a new persist value on the server diff --git a/client/src/test/java/client/ServerUtilsTest.java b/client/src/test/java/client/ServerUtilsTest.java index a493524..67d38a1 100644 --- a/client/src/test/java/client/ServerUtilsTest.java +++ b/client/src/test/java/client/ServerUtilsTest.java @@ -49,7 +49,7 @@ class ServerUtilsTest { void tearDown() throws IOException, InterruptedException { // Not applicable in pipeline testing Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available"); - dv.getRecipes().stream().map(Recipe::getId).forEach(id -> { + dv.getRecipes(List.of()).stream().map(Recipe::getId).forEach(id -> { try { dv.deleteRecipe(id); } catch (Exception ex) { @@ -77,7 +77,7 @@ class ServerUtilsTest { @Test void getAllRecipesTest() throws IOException, InterruptedException { - List recipes = dv.getRecipes(); + List recipes = dv.getRecipes(List.of()); assertNotNull(recipes, "The list should not be null"); assertTrue(recipes.size() >= 0, "The list should be 0 (when no recipes), or more");