MME-9 Transfer ingredients from recipe draft to recipe create spec.
This commit is contained in:
parent
98c89f6247
commit
7f7714b7a3
@ -368,7 +368,7 @@ public class RecipeService {
|
|||||||
public Recipe publishDraft(UUID draftId, User modifier) {
|
public Recipe publishDraft(UUID draftId, User modifier) {
|
||||||
final RecipeDraft recipeDraft = this.recipeDraftRepository.findById(draftId)
|
final RecipeDraft recipeDraft = this.recipeDraftRepository.findById(draftId)
|
||||||
.orElseThrow(() -> new NoSuchEntityWithIdException(RecipeDraft.class, draftId));
|
.orElseThrow(() -> new NoSuchEntityWithIdException(RecipeDraft.class, draftId));
|
||||||
final RecipeCreateSpec spec = RecipeCreateSpec.builder()
|
final var b = RecipeCreateSpec.builder()
|
||||||
.slug(recipeDraft.getSlug())
|
.slug(recipeDraft.getSlug())
|
||||||
.title(recipeDraft.getTitle())
|
.title(recipeDraft.getTitle())
|
||||||
.preparationTime(recipeDraft.getPreparationTime())
|
.preparationTime(recipeDraft.getPreparationTime())
|
||||||
@ -376,8 +376,21 @@ public class RecipeService {
|
|||||||
.totalTime(recipeDraft.getTotalTime())
|
.totalTime(recipeDraft.getTotalTime())
|
||||||
.rawText(recipeDraft.getRawText())
|
.rawText(recipeDraft.getRawText())
|
||||||
.isPublic(false)
|
.isPublic(false)
|
||||||
.mainImage(recipeDraft.getMainImage())
|
.mainImage(recipeDraft.getMainImage());
|
||||||
.build();
|
|
||||||
|
if (recipeDraft.getIngredients() != null) {
|
||||||
|
b.ingredients(recipeDraft.getIngredients().stream()
|
||||||
|
.map(ingredientDraft -> RecipeCreateSpec.IngredientCreateSpec.builder()
|
||||||
|
.amount(ingredientDraft.getAmount())
|
||||||
|
.name(ingredientDraft.getName())
|
||||||
|
.notes(ingredientDraft.getNotes())
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.toList()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final RecipeCreateSpec spec = b.build();
|
||||||
final Recipe recipe = this.create(recipeDraft.getOwner(), spec, true);
|
final Recipe recipe = this.create(recipeDraft.getOwner(), spec, true);
|
||||||
this.recipeDraftRepository.deleteById(draftId); // delete old draft
|
this.recipeDraftRepository.deleteById(draftId); // delete old draft
|
||||||
return recipe;
|
return recipe;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user