Skip to content

Commit

Permalink
Merge pull request #35 from MARKETFUBY/feat/product-detail
Browse files Browse the repository at this point in the history
[차소연] 상품 상세 조회에서 각 리뷰의 이미지 리스트 추가
  • Loading branch information
Soyeon-Cha authored Nov 26, 2023
2 parents 34fc1eb + b7dbc4b commit e8b56a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/MARKETFUBY/Product/dto/ProductReviewDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.Getter;

import java.time.LocalDate;
import java.util.List;

@Getter
@Builder
Expand All @@ -17,17 +18,18 @@ public class ProductReviewDto {
private String brand;
private String title;
private String content;
// private String imgUrl;
private List<String> imageList;
private LocalDate date;
private Boolean isReviewHelp;

public static ProductReviewDto from(Review review, Boolean isReviewHelp){
public static ProductReviewDto from(Review review, List<String> 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();
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/MARKETFUBY/Product/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,26 @@ public List<ProductReviewDto> findReviewsByProduct(Product product, Long memberI
List<Review> reviewList = reviewRepository.findAllByProduct(product);
List<ProductReviewDto> productReviewDtos = new ArrayList<>();
reviewList.forEach(review -> {
List<String> 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<String> findImagesByReview(Review review){
List<ReviewImage> reviewImageList = reviewImageRepository.findAllByReview(review);
return reviewImageList.stream()
.map(ReviewImage::getUrl).collect(Collectors.toList());
}

public List<ProductInquiryDto> findInquiriesByProduct(Product product){
List<Inquiry> inquiryList = inquiryRepository.findAllByProduct(product);
List<ProductInquiryDto> productInquiryDtos = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e8b56a7

Please sign in to comment.