fix(client/serverUtils): immigrate nulling IDs to addRecipe(Recipe)

This commit is contained in:
Zhongheng Liu 2026-01-05 17:07:04 +01:00
commit b60284fa14

View file

@ -83,7 +83,10 @@ 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();
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; int version = 1;
String originalName = newRecipe.getName(); String originalName = newRecipe.getName();
@ -144,11 +147,6 @@ public class ServerUtils {
} }
// recipe exists so you can make a "new" recipe aka the clone // recipe exists so you can make a "new" recipe aka the clone
Recipe recipe = objectMapper.readValue(response.body(), Recipe.class); 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); return addRecipe(recipe);
} }