MME-9 Transfer ingredients from recipe draft to recipe create spec.

This commit is contained in:
Jesse Brault 2026-02-13 10:58:00 -06:00
parent 98c89f6247
commit 7f7714b7a3

View File

@ -368,7 +368,7 @@ public class RecipeService {
public Recipe publishDraft(UUID draftId, User modifier) {
final RecipeDraft recipeDraft = this.recipeDraftRepository.findById(draftId)
.orElseThrow(() -> new NoSuchEntityWithIdException(RecipeDraft.class, draftId));
final RecipeCreateSpec spec = RecipeCreateSpec.builder()
final var b = RecipeCreateSpec.builder()
.slug(recipeDraft.getSlug())
.title(recipeDraft.getTitle())
.preparationTime(recipeDraft.getPreparationTime())
@ -376,8 +376,21 @@ public class RecipeService {
.totalTime(recipeDraft.getTotalTime())
.rawText(recipeDraft.getRawText())
.isPublic(false)
.mainImage(recipeDraft.getMainImage())
.build();
.mainImage(recipeDraft.getMainImage());
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);
this.recipeDraftRepository.deleteById(draftId); // delete old draft
return recipe;