diff --git a/client/src/main/java/client/utils/ServerUtils.java b/client/src/main/java/client/utils/ServerUtils.java index 736b4cd..2e99dbc 100644 --- a/client/src/main/java/client/utils/ServerUtils.java +++ b/client/src/main/java/client/utils/ServerUtils.java @@ -83,7 +83,10 @@ public class ServerUtils { public Recipe addRecipe(Recipe newRecipe) throws IOException, InterruptedException { //Make sure the name of the newRecipe is unique List allRecipes = getRecipes(); - + 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 + newRecipe.getIngredients().forEach(ingredient -> ingredient.setId(null)); int version = 1; String originalName = newRecipe.getName(); @@ -144,11 +147,6 @@ public class ServerUtils { } // recipe exists so you can make a "new" recipe aka the clone Recipe recipe = objectMapper.readValue(response.body(), Recipe.class); - - recipe.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 - recipe.getIngredients().forEach(ingredient -> ingredient.setId(null)); return addRecipe(recipe); }