more tests and debugging

This commit is contained in:
Mei Chang van der Werff 2025-11-27 22:46:42 +01:00
commit b4d6b78656
2 changed files with 37 additions and 16 deletions

View file

@ -51,8 +51,7 @@ public class ServerUtils {
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if(response.statusCode() != statusOK){
System.out.println("No recipe found with this id");
return null;
throw new IOException("No recipe found with this id");
}
return objectMapper.readValue(response.body(),Recipe.class);
@ -62,21 +61,19 @@ public class ServerUtils {
* Adds a recipe to the backend
* @param newRecipe the recipe to be added
* @return a recipe
*/
public Recipe addRecipe(Recipe newRecipe) throws IOException, InterruptedException {
//Make sure the name of the newRecipe is unque
//Make sure the name of the newRecipe is unique
List<Recipe> allRecipes = getRecipes();
boolean exists = allRecipes.stream()
.anyMatch(r -> r.getName().equals(newRecipe.getName()));
if(exists){
int version = 1;
String newName;
// Giving the "new" recipe a unique name
// Giving the recipe a unique name
while (true) {
newName = newRecipe.getName() + "(" + version + ")";
String finalNewName = newName;
@ -90,12 +87,9 @@ public class ServerUtils {
version++;
}
}
}
String json = objectMapper.writeValueAsString(newRecipe);
//Recipe to backend
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(SERVER + "/recipe/new"))