diff --git a/src/main/java/MARKETFUBY/Product/dto/ProductReviewDto.java b/src/main/java/MARKETFUBY/Product/dto/ProductReviewDto.java index 424bc8c..2d6fafe 100644 --- a/src/main/java/MARKETFUBY/Product/dto/ProductReviewDto.java +++ b/src/main/java/MARKETFUBY/Product/dto/ProductReviewDto.java @@ -7,6 +7,7 @@ import lombok.Getter; import java.time.LocalDate; +import java.util.List; @Getter @Builder @@ -17,17 +18,18 @@ public class ProductReviewDto { private String brand; private String title; private String content; - // private String imgUrl; + private List imageList; private LocalDate date; private Boolean isReviewHelp; - public static ProductReviewDto from(Review review, Boolean isReviewHelp){ + public static ProductReviewDto from(Review review, List images, Boolean isReviewHelp){ return ProductReviewDto.builder() .name(review.getWriter().getName()) .level(review.getWriter().getLevel()) .brand(review.getProduct().getBrand()) .title(review.getProduct().getTitle()) .content(review.getContent()) + .imageList(images) .date(review.getCreatedAt().toLocalDate()) .isReviewHelp(isReviewHelp) .build(); diff --git a/src/main/java/MARKETFUBY/Product/service/ProductService.java b/src/main/java/MARKETFUBY/Product/service/ProductService.java index e5dd1e8..baa0701 100644 --- a/src/main/java/MARKETFUBY/Product/service/ProductService.java +++ b/src/main/java/MARKETFUBY/Product/service/ProductService.java @@ -240,19 +240,26 @@ public List findReviewsByProduct(Product product, Long memberI List reviewList = reviewRepository.findAllByProduct(product); List productReviewDtos = new ArrayList<>(); reviewList.forEach(review -> { + List images = findImagesByReview(review); Member member = memberRepository.findByMemberId(memberId); if (member != null) { Boolean isReviewHelp = reviewHelpRepository.existsByMemberAndReview(member, review); - ProductReviewDto productReviewDto = ProductReviewDto.from(review, isReviewHelp); + ProductReviewDto productReviewDto = ProductReviewDto.from(review, images,isReviewHelp); productReviewDtos.add(productReviewDto); } else { - ProductReviewDto productReviewDto = ProductReviewDto.from(review, false); + ProductReviewDto productReviewDto = ProductReviewDto.from(review, images,false); productReviewDtos.add(productReviewDto); } }); return productReviewDtos; } + public List findImagesByReview(Review review){ + List reviewImageList = reviewImageRepository.findAllByReview(review); + return reviewImageList.stream() + .map(ReviewImage::getUrl).collect(Collectors.toList()); + } + public List findInquiriesByProduct(Product product){ List inquiryList = inquiryRepository.findAllByProduct(product); List productInquiryDtos = new ArrayList<>(); diff --git a/src/main/java/MARKETFUBY/ReviewImage/domain/ReviewImage.java b/src/main/java/MARKETFUBY/ReviewImage/domain/ReviewImage.java index 05be640..8e90ba1 100644 --- a/src/main/java/MARKETFUBY/ReviewImage/domain/ReviewImage.java +++ b/src/main/java/MARKETFUBY/ReviewImage/domain/ReviewImage.java @@ -18,6 +18,7 @@ public class ReviewImage { @Column(name = "image_id", updatable = false) private Long imageId; + @Getter @ManyToOne @JoinColumn(name = "review_id", nullable = false) private Review review;