Fixed error when adding ingredient
This commit is contained in:
parent
624a0cbe86
commit
f048e0fe3e
2 changed files with 9 additions and 6 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package server.service;
|
||||
|
||||
import commons.Ingredient;
|
||||
import commons.Recipe;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -88,8 +89,11 @@ public class RecipeService {
|
|||
recipeIngredient.setIngredient(
|
||||
ingredientRepository
|
||||
.findByName(recipeIngredient.getIngredient().name)
|
||||
.orElseGet(() -> ingredientRepository.save(recipeIngredient.getIngredient())
|
||||
))
|
||||
.orElseGet(() -> {
|
||||
Ingredient i = recipeIngredient.getIngredient();
|
||||
i.setId(null);
|
||||
return ingredientRepository.save(i);
|
||||
}))
|
||||
);
|
||||
recipeIngredientRepository.saveAll(recipe.getIngredients());
|
||||
return recipeRepository.save(recipe);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue