fix: pipeline not passing

This commit is contained in:
Natalia Cholewa 2026-01-09 23:49:10 +01:00
commit 453e5b11bd
4 changed files with 17 additions and 13 deletions

View file

@ -268,7 +268,10 @@ public class FoodpalApplicationCtrl implements LocaleAware {
public void refresh() {
List<Recipe> 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();

View file

@ -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<List<Recipe>> onSearchCallback;
@ -41,9 +43,10 @@ public class SearchBarCtrl implements LocaleAware {
private Task<List<Recipe>> 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<Recipe> call() throws IOException, InterruptedException {
return serverUtils.getRecipesFiltered(filter);
return serverUtils.getRecipesFiltered(filter, configService.getConfig().getRecipeLanguages());
}
};

View file

@ -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<Recipe> getRecipes() throws IOException, InterruptedException {
public List<Recipe> getRecipes(List<String> 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<Recipe> (Jackson)
}
public List<Recipe> getRecipesFiltered(String filter) throws IOException, InterruptedException {
public List<Recipe> getRecipesFiltered(String filter, List<String> 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<Recipe> allRecipes = getRecipes();
List<Recipe> 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

View file

@ -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<Recipe> recipes = dv.getRecipes();
List<Recipe> 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");