From 7540882ab3f7e527a16500fdbb482a07d35dc2c2 Mon Sep 17 00:00:00 2001 From: 70825 Date: Thu, 23 May 2024 11:34:22 +0900 Subject: [PATCH 1/2] =?UTF-8?q?test:=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=ED=83=9C=EA=B7=B8=EB=8F=84=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=B4=EC=95=BC=ED=95=B4=EC=84=9C=20MemberRviewDto.toDto=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/review/application/ReviewServiceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() From 474677237017731e0c79e7ef79b07b89346a6d6a Mon Sep 17 00:00:00 2001 From: 70825 Date: Thu, 23 May 2024 11:37:35 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20DTO=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=EB=B0=8F=20=ED=83=9C=EA=B7=B8=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?DTO=20=EB=B3=80=ED=99=98=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/member/dto/MemberReviewDto.java | 44 +++++++++++++------ .../review/application/ReviewService.java | 10 ++++- 2 files changed, 38 insertions(+), 16 deletions(-) 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)