diff --git a/src/main/java/com/funeat/member/dto/MemberReviewDto.java b/src/main/java/com/funeat/member/dto/MemberReviewDto.java index 082b4dd7..eaf70ef2 100644 --- a/src/main/java/com/funeat/member/dto/MemberReviewDto.java +++ b/src/main/java/com/funeat/member/dto/MemberReviewDto.java @@ -1,38 +1,50 @@ package com.funeat.member.dto; import com.funeat.review.domain.Review; +import com.funeat.tag.domain.Tag; +import com.funeat.tag.dto.TagDto; + +import java.time.LocalDateTime; +import java.util.List; public class MemberReviewDto { private final Long reviewId; private final Long productId; - private final String categoryType; private final String productName; private final String content; private final Long rating; - private final Long favoriteCount; + private final List tags; + private final String image; + private final LocalDateTime createdAt; - private MemberReviewDto(final Long reviewId, final Long productId, final String categoryType, - final String productName, final String content, - final Long rating, final Long favoriteCount) { + private MemberReviewDto(final Long reviewId, final Long productId, final String productName, + final String content, final Long rating, final List tags, final String image, + final LocalDateTime createdAt) { this.reviewId = reviewId; this.productId = productId; - this.categoryType = categoryType; this.productName = productName; this.content = content; this.rating = rating; - this.favoriteCount = favoriteCount; + this.tags = tags; + this.image = image; + this.createdAt = createdAt; } - public static MemberReviewDto toDto(final Review review) { + public static MemberReviewDto toDto(final Review review, final List tags) { + final List tagDtos = tags.stream() + .map(TagDto::toDto) + .toList(); + return new MemberReviewDto( review.getId(), review.getProduct().getId(), - review.getProduct().getCategory().getType().getName(), review.getProduct().getName(), review.getContent(), review.getRating(), - review.getFavoriteCount() + tagDtos, + review.getImage(), + review.getCreatedAt() ); } @@ -56,11 +68,15 @@ public Long getRating() { return rating; } - public Long getFavoriteCount() { - return favoriteCount; + public List getTags() { + return tags; + } + + public String getImage() { + return image; } - public String getCategoryType() { - return categoryType; + public LocalDateTime getCreatedAt() { + return createdAt; } } diff --git a/src/main/java/com/funeat/review/application/ReviewService.java b/src/main/java/com/funeat/review/application/ReviewService.java index f9f12b97..586658ea 100644 --- a/src/main/java/com/funeat/review/application/ReviewService.java +++ b/src/main/java/com/funeat/review/application/ReviewService.java @@ -231,12 +231,18 @@ public MemberReviewsResponse findReviewByMember(final Long memberId, final Pagea final PageDto pageDto = PageDto.toDto(sortedReviewPages); final List dtos = sortedReviewPages.stream() - .map(MemberReviewDto::toDto) - .collect(Collectors.toList()); + .map(this::transformMemberReviewDtoWithReviewAndTag) + .toList(); return MemberReviewsResponse.toResponse(pageDto, dtos); } + private MemberReviewDto transformMemberReviewDtoWithReviewAndTag(final Review review) { + final List tags = tagRepository.findTagsByReviewId(review.getId()); + + return MemberReviewDto.toDto(review, tags); + } + @Transactional public void deleteReview(final Long reviewId, final Long memberId) { final Member member = memberRepository.findById(memberId) diff --git a/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/src/test/java/com/funeat/review/application/ReviewServiceTest.java index 0c6a3880..b701501d 100644 --- a/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -680,8 +680,8 @@ class findReviewByMember_성공_테스트 { // then final var expectedReviews = List.of(review3_1, review2_1, review1_1); final var expectedReviewDtos = expectedReviews.stream() - .map(MemberReviewDto::toDto) - .collect(Collectors.toList()); + .map(review -> MemberReviewDto.toDto(review, Collections.emptyList())) + .toList(); final var expectedPage = new PageDto(3L, 1L, true, true, 0L, 10L); assertThat(result.getReviews()).usingRecursiveComparison()