fix(client/serverUtils): immigrate nulling IDs to addRecipe(Recipe)
This commit is contained in:
parent
7bb2b06679
commit
b60284fa14
1 changed files with 4 additions and 6 deletions
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue