Skip to content

Commit

Permalink
#9 feat: 레시피글 상세 조회 시 댓글도 함께 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
JoongHyun-Kim committed Feb 26, 2024
1 parent 3dcdf4d commit 34e6bf9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.kkobugi.puremarket.comment.domain.entity.Comment;
import com.kkobugi.puremarket.giveaway.domain.entity.Giveaway;
import com.kkobugi.puremarket.produce.domain.entity.Produce;
import com.kkobugi.puremarket.recipe.domain.entity.Recipe;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findByGiveawayOrderByCreatedDateAsc(Giveaway giveaway);
List<Comment> findByProduceOrderByCreatedDateAsc(Produce produce);
List<Comment> findByRecipeOrderByCreatedDateAsc(Recipe recipe);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.kkobugi.puremarket.recipe.application;

import com.kkobugi.puremarket.comment.domain.dto.CommentDto;
import com.kkobugi.puremarket.comment.repository.CommentRepository;
import com.kkobugi.puremarket.common.BaseException;
import com.kkobugi.puremarket.common.gcs.GCSService;
import com.kkobugi.puremarket.ingredient.domain.entity.Ingredient;
Expand All @@ -19,6 +21,7 @@
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.stream.Collectors;

import static com.kkobugi.puremarket.common.constants.Constant.ACTIVE;
import static com.kkobugi.puremarket.common.constants.Constant.INACTIVE;
Expand All @@ -35,6 +38,7 @@ public class RecipeService {
private final RecipeDescriptionRepository recipeDescriptionRepository;
private final UserRepository userRepository;
private final GCSService gcsService;
private final CommentRepository commentRepository;

@Value("${spring.cloud.gcp.storage.bucket}")
private String bucketName;
Expand Down Expand Up @@ -71,9 +75,13 @@ public RecipeResponse getRecipe(Long recipeIdx) throws BaseException {
List<SauceDto> sauceList = getSauceList(recipe);
List<RecipeDescriptionDto> recipeDescriptionList = getRecipeDescriptionList(recipe);

List<CommentDto> commentList = commentRepository.findByRecipeOrderByCreatedDateAsc(recipe).stream()
.map(comment -> new CommentDto(comment.getUser().getNickname(), comment.getUser().getProfileImage(),
comment.getContent(), comment.getCreatedDate())).collect(Collectors.toList());

return new RecipeResponse(recipe.getRecipeIdx(), recipe.getTitle(), recipe.getContent(), recipe.getRecipeImage(),
ingredientList, sauceList, recipeDescriptionList,
recipe.getUser().getNickname(), recipe.getUser().getContact(), recipe.getUser().getProfileImage(), isWriter);
ingredientList, sauceList, recipeDescriptionList, recipe.getUser().getNickname(), recipe.getUser().getContact(),
recipe.getUser().getProfileImage(), isWriter, commentList);
} catch (BaseException e) {
throw e;
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kkobugi.puremarket.recipe.domain.dto;

import com.kkobugi.puremarket.comment.domain.dto.CommentDto;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;
Expand Down Expand Up @@ -27,4 +28,6 @@ public record RecipeResponse(
@Schema(description = "프로필 이미지 url", example = "https://dwffwdfdwbwv")
String profileImage,
@Schema(description = "글 작성자 여부", example = "true")
boolean isWriter) {}
boolean isWriter,
@Schema(description = "댓글 리스트")
List<CommentDto> commentList) {}

0 comments on commit 34e6bf9

Please sign in to comment.