From 7f7714b7a3fe1a45de26bc558bc850d3b89e011e Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Fri, 13 Feb 2026 10:58:00 -0600 Subject: [PATCH] MME-9 Transfer ingredients from recipe draft to recipe create spec. --- .../api/recipe/RecipeService.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/app/mealsmadeeasy/api/recipe/RecipeService.java b/src/main/java/app/mealsmadeeasy/api/recipe/RecipeService.java index 10526e5..b32cd0e 100644 --- a/src/main/java/app/mealsmadeeasy/api/recipe/RecipeService.java +++ b/src/main/java/app/mealsmadeeasy/api/recipe/RecipeService.java @@ -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;