fix: pipeline not passing
This commit is contained in:
parent
b130381154
commit
453e5b11bd
4 changed files with 17 additions and 13 deletions
|
|
@ -268,7 +268,10 @@ public class FoodpalApplicationCtrl implements LocaleAware {
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
List<Recipe> recipes;
|
List<Recipe> recipes;
|
||||||
try {
|
try {
|
||||||
recipes = server.getRecipesFiltered(searchBarController.getFilter());
|
recipes = server.getRecipesFiltered(
|
||||||
|
searchBarController.getFilter(),
|
||||||
|
this.configService.getConfig().getRecipeLanguages()
|
||||||
|
);
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
recipes = Collections.emptyList();
|
recipes = Collections.emptyList();
|
||||||
String msg = "Failed to load recipes: " + e.getMessage();
|
String msg = "Failed to load recipes: " + e.getMessage();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package client.scenes;
|
package client.scenes;
|
||||||
|
|
||||||
|
import client.utils.ConfigService;
|
||||||
import client.utils.LocaleAware;
|
import client.utils.LocaleAware;
|
||||||
import client.utils.LocaleManager;
|
import client.utils.LocaleManager;
|
||||||
import client.utils.ServerUtils;
|
import client.utils.ServerUtils;
|
||||||
|
|
@ -28,6 +29,7 @@ public class SearchBarCtrl implements LocaleAware {
|
||||||
|
|
||||||
private final LocaleManager localeManager;
|
private final LocaleManager localeManager;
|
||||||
private final ServerUtils serverUtils;
|
private final ServerUtils serverUtils;
|
||||||
|
private final ConfigService configService;
|
||||||
|
|
||||||
private Consumer<List<Recipe>> onSearchCallback;
|
private Consumer<List<Recipe>> onSearchCallback;
|
||||||
|
|
||||||
|
|
@ -41,9 +43,10 @@ public class SearchBarCtrl implements LocaleAware {
|
||||||
private Task<List<Recipe>> currentSearchTask = null;
|
private Task<List<Recipe>> currentSearchTask = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SearchBarCtrl(LocaleManager localeManager, ServerUtils serverUtils) {
|
public SearchBarCtrl(LocaleManager localeManager, ServerUtils serverUtils, ConfigService configService) {
|
||||||
this.localeManager = localeManager;
|
this.localeManager = localeManager;
|
||||||
this.serverUtils = serverUtils;
|
this.serverUtils = serverUtils;
|
||||||
|
this.configService = configService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
|
@ -96,7 +99,7 @@ public class SearchBarCtrl implements LocaleAware {
|
||||||
currentSearchTask = new Task<>() {
|
currentSearchTask = new Task<>() {
|
||||||
@Override
|
@Override
|
||||||
protected List<Recipe> call() throws IOException, InterruptedException {
|
protected List<Recipe> call() throws IOException, InterruptedException {
|
||||||
return serverUtils.getRecipesFiltered(filter);
|
return serverUtils.getRecipesFiltered(filter, configService.getConfig().getRecipeLanguages());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,9 @@ public class ServerUtils {
|
||||||
private final HttpClient client;
|
private final HttpClient client;
|
||||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
private final int statusOK = 200;
|
private final int statusOK = 200;
|
||||||
private final ConfigService configService;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ServerUtils(ConfigService configService) {
|
public ServerUtils() {
|
||||||
this.configService = configService;
|
|
||||||
client = HttpClient.newHttpClient();
|
client = HttpClient.newHttpClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -41,13 +39,13 @@ public class ServerUtils {
|
||||||
* Gets all the recipes from the backend.
|
* Gets all the recipes from the backend.
|
||||||
* @return a JSON string with all the recipes
|
* @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 =
|
String uri =
|
||||||
SERVER +
|
SERVER +
|
||||||
"/recipes" +
|
"/recipes" +
|
||||||
"?locales=" +
|
"?locales=" +
|
||||||
String.join(",", this.configService.getConfig().getRecipeLanguages());
|
String.join(",", locales);
|
||||||
|
|
||||||
HttpRequest request = HttpRequest.newBuilder()
|
HttpRequest request = HttpRequest.newBuilder()
|
||||||
.uri(URI.create(uri))
|
.uri(URI.create(uri))
|
||||||
|
|
@ -65,9 +63,9 @@ public class ServerUtils {
|
||||||
return list; // JSON string-> List<Recipe> (Jackson)
|
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
|
// 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 {
|
public Recipe addRecipe(Recipe newRecipe) throws IOException, InterruptedException {
|
||||||
//Make sure the name of the newRecipe is unique
|
//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
|
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,
|
// 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
|
// we set that to null too to force a new persist value on the server
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ class ServerUtilsTest {
|
||||||
void tearDown() throws IOException, InterruptedException {
|
void tearDown() throws IOException, InterruptedException {
|
||||||
// Not applicable in pipeline testing
|
// Not applicable in pipeline testing
|
||||||
Assumptions.assumeTrue(dv.isServerAvailable(), "Server not available");
|
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 {
|
try {
|
||||||
dv.deleteRecipe(id);
|
dv.deleteRecipe(id);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
|
@ -77,7 +77,7 @@ class ServerUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getAllRecipesTest() throws IOException, InterruptedException {
|
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");
|
assertNotNull(recipes, "The list should not be null");
|
||||||
assertTrue(recipes.size() >= 0, "The list should be 0 (when no recipes), or more");
|
assertTrue(recipes.size() >= 0, "The list should be 0 (when no recipes), or more");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue