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) ); }