Skip to content

Commit

Permalink
♻️ add constructor to MainRecipeResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
oshyun00 committed Aug 17, 2024
1 parent 979db60 commit ee73797
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -19,4 +20,28 @@ public record MainRecipeResponse(
List<IngredientResponse> ingredient,
boolean mine
) {

public MainRecipeResponse(
UserInfo userInfo,
RecipeDataResponse firstResponse,
List<CategoryResponse> category,
List<IngredientResponse> 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())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -112,22 +111,12 @@ private List<MainRecipeResponse> convertToMainRecipeResponses(

private MainRecipeResponse getMainRecipeResponse(UserInfo userInfo, List<RecipeDataResponse> 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)
);
}

Expand Down

0 comments on commit ee73797

Please sign in to comment.