From ee737979eece47b8135e6378674c068712bd6a74 Mon Sep 17 00:00:00 2001 From: hyun Date: Fri, 16 Aug 2024 21:55:31 +0900 Subject: [PATCH] :recycle: add constructor to MainRecipeResponse --- .../recipe/dto/MainRecipeResponse.java | 25 +++++++++++++++++++ .../recipe/service/RecipeService.java | 17 +++---------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/net/pengcook/recipe/dto/MainRecipeResponse.java b/backend/src/main/java/net/pengcook/recipe/dto/MainRecipeResponse.java index d775116b..80cc5300 100644 --- a/backend/src/main/java/net/pengcook/recipe/dto/MainRecipeResponse.java +++ b/backend/src/main/java/net/pengcook/recipe/dto/MainRecipeResponse.java @@ -3,6 +3,7 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; +import net.pengcook.authentication.domain.UserInfo; public record MainRecipeResponse( long recipeId, @@ -19,4 +20,28 @@ public record MainRecipeResponse( List ingredient, boolean mine ) { + + public MainRecipeResponse( + UserInfo userInfo, + RecipeDataResponse firstResponse, + List category, + List ingredient + + ) { + this( + firstResponse.recipeId(), + firstResponse.title(), + new AuthorResponse(firstResponse.authorId(), firstResponse.authorName(), firstResponse.authorImage()), + firstResponse.cookingTime(), + firstResponse.thumbnail(), + firstResponse.difficulty(), + firstResponse.likeCount(), + firstResponse.commentCount(), + firstResponse.description(), + firstResponse.createdAt(), + category, + ingredient, + userInfo.isSameUser(firstResponse.authorId()) + ); + } } diff --git a/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java b/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java index 48743e35..f3b9eb25 100644 --- a/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java +++ b/backend/src/main/java/net/pengcook/recipe/service/RecipeService.java @@ -15,7 +15,6 @@ import net.pengcook.ingredient.service.IngredientService; import net.pengcook.like.service.RecipeLikeService; import net.pengcook.recipe.domain.Recipe; -import net.pengcook.recipe.dto.AuthorResponse; import net.pengcook.recipe.dto.CategoryResponse; import net.pengcook.recipe.dto.IngredientResponse; import net.pengcook.recipe.dto.MainRecipeResponse; @@ -112,22 +111,12 @@ private List convertToMainRecipeResponses( private MainRecipeResponse getMainRecipeResponse(UserInfo userInfo, List groupedResponses) { RecipeDataResponse firstResponse = groupedResponses.getFirst(); - boolean mine = firstResponse.authorId() == userInfo.getId(); return new MainRecipeResponse( - firstResponse.recipeId(), - firstResponse.title(), - new AuthorResponse(firstResponse.authorId(), firstResponse.authorName(), firstResponse.authorImage()), - firstResponse.cookingTime(), - firstResponse.thumbnail(), - firstResponse.difficulty(), - firstResponse.likeCount(), - firstResponse.commentCount(), - firstResponse.description(), - firstResponse.createdAt(), + userInfo, + firstResponse, getCategoryResponses(groupedResponses), - getIngredientResponses(groupedResponses), - mine + getIngredientResponses(groupedResponses) ); }