From e75573684372937c40b81db2759de7e04418cfbe Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Thu, 6 Jun 2024 21:46:29 +0900 Subject: [PATCH 1/7] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20=EB=9E=AD?= =?UTF-8?q?=ED=82=B9=20dto=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/review/dto/RankingReviewDto.java | 62 +++++++++++++++---- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/funeat/review/dto/RankingReviewDto.java b/src/main/java/com/funeat/review/dto/RankingReviewDto.java index 42f0102e..5b3e1da3 100644 --- a/src/main/java/com/funeat/review/dto/RankingReviewDto.java +++ b/src/main/java/com/funeat/review/dto/RankingReviewDto.java @@ -7,27 +7,38 @@ public class RankingReviewDto { - private final Long reviewId; + private final Long id; + private final String userName; + private final String profileImage; private final Long productId; - private final String categoryType; private final String productName; private final String content; private final String image; + private final Long rating; + private final boolean rebuy; + private final Long favoriteCount; + private final boolean favorite; private final List tags; - private RankingReviewDto(final Long reviewId, final Long productId, final String categoryType, + private RankingReviewDto(final Long id, final String userName, final String profileImage, final Long productId, final String productName, final String content, final String image, + final Long rating, final boolean rebuy, final Long favoriteCount, final boolean favorite, final List tags) { - this.reviewId = reviewId; + this.id = id; + this.userName = userName; + this.profileImage = profileImage; this.productId = productId; - this.categoryType = categoryType; this.productName = productName; this.content = content; this.image = image; + this.rating = rating; + this.rebuy = rebuy; + this.favoriteCount = favoriteCount; + this.favorite = favorite; this.tags = tags; } - public static RankingReviewDto toDto(final Review review) { + public static RankingReviewDto toDto(final Review review, final Boolean favorite) { final List tagDtos = review.getReviewTags().stream() .map(ReviewTag::getTag) .map(TagDto::toDto) @@ -35,17 +46,30 @@ public static RankingReviewDto toDto(final Review review) { return new RankingReviewDto( review.getId(), + review.getMember().getNickname(), + review.getMember().getProfileImage(), review.getProduct().getId(), - review.getProduct().getCategory().getType().getName(), review.getProduct().getName(), review.getContent(), review.getImage(), + review.getRating(), + review.getReBuy(), + review.getFavoriteCount(), + favorite, tagDtos ); } - public Long getReviewId() { - return reviewId; + public Long getId() { + return id; + } + + public String getUserName() { + return userName; + } + + public String getProfileImage() { + return profileImage; } public Long getProductId() { @@ -60,14 +84,26 @@ public String getContent() { return content; } - public String getCategoryType() { - return categoryType; - } - public String getImage() { return image; } + public Long getRating() { + return rating; + } + + public boolean isRebuy() { + return rebuy; + } + + public Long getFavoriteCount() { + return favoriteCount; + } + + public boolean isFavorite() { + return favorite; + } + public List getTags() { return tags; } From 7ed7d56a5537d5f0c743f199ce713bda9cac1cd5 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Thu, 6 Jun 2024 21:47:06 +0900 Subject: [PATCH 2/7] =?UTF-8?q?refactor:=20=EB=B9=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EC=8B=9C=EC=97=90=EB=8F=84=20LoginInfo=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/funeat/review/presentation/ReviewApiController.java | 6 +++--- .../com/funeat/review/presentation/ReviewController.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/funeat/review/presentation/ReviewApiController.java b/src/main/java/com/funeat/review/presentation/ReviewApiController.java index 886ed8ac..eb9ad90e 100644 --- a/src/main/java/com/funeat/review/presentation/ReviewApiController.java +++ b/src/main/java/com/funeat/review/presentation/ReviewApiController.java @@ -11,9 +11,9 @@ import com.funeat.review.dto.ReviewFavoriteRequest; import com.funeat.review.dto.SortingReviewRequest; import com.funeat.review.dto.SortingReviewsResponse; +import jakarta.validation.Valid; import java.net.URI; import java.util.Optional; -import jakarta.validation.Valid; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -68,8 +68,8 @@ public ResponseEntity getSortingReviews(@AuthenticationP } @GetMapping("/api/ranks/reviews") - public ResponseEntity getRankingReviews() { - final RankingReviewsResponse response = reviewService.getTopReviews(); + public ResponseEntity getRankingReviews(@AuthenticationPrincipal final LoginInfo loginInfo) { + final RankingReviewsResponse response = reviewService.getTopReviews(loginInfo.getId()); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/funeat/review/presentation/ReviewController.java b/src/main/java/com/funeat/review/presentation/ReviewController.java index 13fb85e9..18ab1c26 100644 --- a/src/main/java/com/funeat/review/presentation/ReviewController.java +++ b/src/main/java/com/funeat/review/presentation/ReviewController.java @@ -64,7 +64,7 @@ ResponseEntity getSortingReviews(@AuthenticationPrincipa description = "리뷰 랭킹 Top3 조회 성공." ) @GetMapping - ResponseEntity getRankingReviews(); + ResponseEntity getRankingReviews(@AuthenticationPrincipal final LoginInfo loginInfo); @Operation(summary = "좋아요를 제일 많은 받은 리뷰 조회", description = "특정 상품에 대해 좋아요를 제일 많이 받은 리뷰를 조회한다.") @ApiResponse( From 37759c875489a41dd0ece35dffb72d7f39b2bc12 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Thu, 6 Jun 2024 21:47:49 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20=EB=9E=AD?= =?UTF-8?q?=ED=82=B9=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/ReviewFavoriteRepository.java | 2 ++ .../review/application/ReviewService.java | 19 +++++++++--- .../review/ReviewAcceptanceTest.java | 3 +- .../review/application/ReviewServiceTest.java | 31 +++++++++++-------- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/funeat/member/persistence/ReviewFavoriteRepository.java b/src/main/java/com/funeat/member/persistence/ReviewFavoriteRepository.java index f1ae40e5..a79fc986 100644 --- a/src/main/java/com/funeat/member/persistence/ReviewFavoriteRepository.java +++ b/src/main/java/com/funeat/member/persistence/ReviewFavoriteRepository.java @@ -14,4 +14,6 @@ public interface ReviewFavoriteRepository extends JpaRepository findByReview(final Review review); + + boolean existsByMemberAndReviewAndFavoriteTrue(final Member member, final Review review); } diff --git a/src/main/java/com/funeat/review/application/ReviewService.java b/src/main/java/com/funeat/review/application/ReviewService.java index 586658ea..314e162a 100644 --- a/src/main/java/com/funeat/review/application/ReviewService.java +++ b/src/main/java/com/funeat/review/application/ReviewService.java @@ -63,6 +63,7 @@ public class ReviewService { private static final int RANKING_SIZE = 2; private static final long RANKING_MINIMUM_FAVORITE_COUNT = 1L; private static final int REVIEW_PAGE_SIZE = 10; + private static final long GUEST_ID = -1L; private final ReviewRepository reviewRepository; private final TagRepository tagRepository; @@ -212,17 +213,27 @@ private Boolean hasNextPage(final List sortingReviews) { return sortingReviews.size() > REVIEW_PAGE_SIZE; } - public RankingReviewsResponse getTopReviews() { + public RankingReviewsResponse getTopReviews(final Long memberId) { final List reviews = reviewRepository.findReviewsByFavoriteCountGreaterThanEqual(RANKING_MINIMUM_FAVORITE_COUNT); final List dtos = reviews.stream() .sorted(Comparator.comparing(Review::calculateRankingScore).reversed()) .limit(RANKING_SIZE) - .map(RankingReviewDto::toDto) - .collect(Collectors.toList()); - + .map(review -> createRankingReviewDto(memberId, review)) + .toList(); return RankingReviewsResponse.toResponse(dtos); } + private RankingReviewDto createRankingReviewDto(final Long memberId, final Review review) { + if (memberId == GUEST_ID) { + return RankingReviewDto.toDto(review, false); + } + + final Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); + final Boolean favorite = reviewFavoriteRepository.existsByMemberAndReviewAndFavoriteTrue(member, review); + return RankingReviewDto.toDto(review, favorite); + } + public MemberReviewsResponse findReviewByMember(final Long memberId, final Pageable pageable) { final Member findMember = memberRepository.findById(memberId) .orElseThrow(() -> new MemberNotFoundException(MEMBER_NOT_FOUND, memberId)); diff --git a/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index c3a9ab61..4ac965f0 100644 --- a/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -10,7 +10,6 @@ import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.common.CommonSteps.정상_처리_NO_CONTENT; import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; -import static com.funeat.acceptance.product.ProductSteps.상품_상세_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_랭킹_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_상세_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_작성_요청; @@ -852,7 +851,7 @@ class getReviewDetail_실패_테스트 { final var actual = response.jsonPath() .getList("reviews", RankingReviewDto.class); - assertThat(actual).extracting(RankingReviewDto::getReviewId) + assertThat(actual).extracting(RankingReviewDto::getId) .containsExactlyElementsOf(reviewIds); } diff --git a/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/src/test/java/com/funeat/review/application/ReviewServiceTest.java index b701501d..0baa6a15 100644 --- a/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -1206,10 +1206,11 @@ class 리뷰_개수에_대한_테스트 { @Test void 전체_리뷰가_하나도_없어도_반환값은_있어야한다() { // given + final var loginId = -1L; final var expected = RankingReviewsResponse.toResponse(Collections.emptyList()); // when - final var actual = reviewService.getTopReviews(); + final var actual = reviewService.getTopReviews(loginId); // then assertThat(actual).usingRecursiveComparison() @@ -1219,6 +1220,7 @@ class 리뷰_개수에_대한_테스트 { @Test void 전체_리뷰가_1개라도_리뷰가_나와야한다() { // given + final var loginId = -1L; final var category = 카테고리_간편식사_생성(); 단일_카테고리_저장(category); @@ -1232,12 +1234,12 @@ class 리뷰_개수에_대한_테스트 { final var review = 리뷰_이미지test5_평점5점_재구매X_생성(member, product, 2L, now.minusDays(1L)); 단일_리뷰_저장(review); - final var rankingReviewDto = RankingReviewDto.toDto(review); + final var rankingReviewDto = RankingReviewDto.toDto(review, false); final var rankingReviewDtos = List.of(rankingReviewDto); final var expected = RankingReviewsResponse.toResponse(rankingReviewDtos); // when - final var actual = reviewService.getTopReviews(); + final var actual = reviewService.getTopReviews(loginId); // then assertThat(actual).usingRecursiveComparison() @@ -1247,6 +1249,7 @@ class 리뷰_개수에_대한_테스트 { @Test void 전체_리뷰_중_랭킹이_높은_상위_2개_리뷰를_구할_수_있다() { // given + final var loginId = -1L; final var category = 카테고리_간편식사_생성(); 단일_카테고리_저장(category); @@ -1262,14 +1265,14 @@ class 리뷰_개수에_대한_테스트 { final var review3 = 리뷰_이미지test5_평점5점_재구매X_생성(member, product, 4L, now); 복수_리뷰_저장(review1, review2, review3); - final var rankingReviewDto1 = RankingReviewDto.toDto(review1); - final var rankingReviewDto2 = RankingReviewDto.toDto(review2); - final var rankingReviewDto3 = RankingReviewDto.toDto(review3); + final var rankingReviewDto1 = RankingReviewDto.toDto(review1, false); + final var rankingReviewDto2 = RankingReviewDto.toDto(review2, false); + final var rankingReviewDto3 = RankingReviewDto.toDto(review3, false); final var rankingReviewDtos = List.of(rankingReviewDto3, rankingReviewDto2); final var expected = RankingReviewsResponse.toResponse(rankingReviewDtos); // when - final var actual = reviewService.getTopReviews(); + final var actual = reviewService.getTopReviews(loginId); // then assertThat(actual).usingRecursiveComparison() @@ -1283,6 +1286,7 @@ class 리뷰_랭킹_점수에_대한_테스트 { @Test void 리뷰_좋아요_수가_같으면_최근_생성된_리뷰의_랭킹을_더_높게_반환한다() { // given + final var loginId = -1L; final var category = 카테고리_간편식사_생성(); 단일_카테고리_저장(category); @@ -1297,13 +1301,13 @@ class 리뷰_랭킹_점수에_대한_테스트 { final var review2 = 리뷰_이미지test5_평점5점_재구매X_생성(member, product, 10L, now.minusDays(4L)); 복수_리뷰_저장(review1, review2); - final var rankingReviewDto1 = RankingReviewDto.toDto(review1); - final var rankingReviewDto2 = RankingReviewDto.toDto(review2); + final var rankingReviewDto1 = RankingReviewDto.toDto(review1, false); + final var rankingReviewDto2 = RankingReviewDto.toDto(review2, false); final var rankingReviewDtos = List.of(rankingReviewDto2, rankingReviewDto1); final var expected = RankingReviewsResponse.toResponse(rankingReviewDtos); // when - final var actual = reviewService.getTopReviews(); + final var actual = reviewService.getTopReviews(loginId); // then assertThat(actual).usingRecursiveComparison() @@ -1313,6 +1317,7 @@ class 리뷰_랭킹_점수에_대한_테스트 { @Test void 리뷰_생성_일자가_같으면_좋아요_수가_많은_리뷰의_랭킹을_더_높게_반환한다() { // given + final var loginId = -1L; final var category = 카테고리_간편식사_생성(); 단일_카테고리_저장(category); @@ -1327,13 +1332,13 @@ class 리뷰_랭킹_점수에_대한_테스트 { final var review2 = 리뷰_이미지test5_평점5점_재구매X_생성(member, product, 4L, now.minusDays(1L)); 복수_리뷰_저장(review1, review2); - final var rankingReviewDto1 = RankingReviewDto.toDto(review1); - final var rankingReviewDto2 = RankingReviewDto.toDto(review2); + final var rankingReviewDto1 = RankingReviewDto.toDto(review1, false); + final var rankingReviewDto2 = RankingReviewDto.toDto(review2, false); final var rankingReviewDtos = List.of(rankingReviewDto2, rankingReviewDto1); final var expected = RankingReviewsResponse.toResponse(rankingReviewDtos); // when - final var actual = reviewService.getTopReviews(); + final var actual = reviewService.getTopReviews(loginId); // then assertThat(actual).usingRecursiveComparison() From 4e882600a022bd7780cf4b9457614e89eb7baedc Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Thu, 6 Jun 2024 21:55:16 +0900 Subject: [PATCH 4/7] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=9E=AD=ED=82=B9=20=EC=9D=B8=EC=88=98=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../review/ReviewAcceptanceTest.java | 35 +++++++++++++++++-- .../funeat/acceptance/review/ReviewSteps.java | 9 +++++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index 4ac965f0..64aa29c3 100644 --- a/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -714,7 +714,7 @@ class getSortingReviews_비로그인_사용자_실패_테스트 { class getRankingReviews_성공_테스트 { @Test - void 리뷰_랭킹을_조회하다() { + void 로그인을_하지_않고_리뷰_랭킹을_조회한다() { // given final var 카테고리 = 카테고리_즉석조리_생성(); 단일_카테고리_저장(카테고리); @@ -736,7 +736,33 @@ class getRankingReviews_성공_테스트 { // then STATUS_CODE를_검증한다(응답, 정상_처리); - 리뷰_랭킹_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3)); + 리뷰_랭킹_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3), List.of(false, false)); + } + + @Test + void 로그인_후_리뷰_랭킹을_조회한다() { + // given + final var 카테고리 = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(카테고리); + final var 상품1 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점3점_생성(카테고리)); + final var 상품2 = 단일_상품_저장(상품_삼각김밥_가격2000원_평점3점_생성(카테고리)); + final var 태그 = 단일_태그_저장(태그_맛있어요_TASTE_생성()); + + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품1, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품1, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품1, 사진_명세_요청(이미지3), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품2, 사진_명세_요청(이미지4), 리뷰추가요청_재구매O_생성(점수_5점, List.of(태그))); + 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품2, 사진_명세_요청(이미지5), 리뷰추가요청_재구매O_생성(점수_1점, List.of(태그))); + 여러명이_리뷰_좋아요_요청(List.of(멤버1, 멤버2, 멤버3), 상품1, 리뷰2, 좋아요O); + 여러명이_리뷰_좋아요_요청(List.of(멤버1, 멤버2), 상품1, 리뷰3, 좋아요O); + 여러명이_리뷰_좋아요_요청(List.of(멤버1), 상품1, 리뷰4, 좋아요O); + + // when + final var 응답 = 리뷰_랭킹_조회_요청(로그인_쿠키_획득(멤버2)); + + // then + STATUS_CODE를_검증한다(응답, 정상_처리); + 리뷰_랭킹_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3), List.of(true, true)); } } @@ -847,12 +873,15 @@ class getReviewDetail_실패_테스트 { .containsExactlyElementsOf(reviewIds); } - private void 리뷰_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List reviewIds) { + private void 리뷰_랭킹_조회_결과를_검증한다(final ExtractableResponse response, final List reviewIds, + final List favorites) { final var actual = response.jsonPath() .getList("reviews", RankingReviewDto.class); assertThat(actual).extracting(RankingReviewDto::getId) .containsExactlyElementsOf(reviewIds); + assertThat(actual).extracting(RankingReviewDto::isFavorite) + .isEqualTo(favorites); } private void 좋아요를_제일_많이_받은_리뷰_결과를_검증한다(final ExtractableResponse response, final Long reviewId) { diff --git a/src/test/java/com/funeat/acceptance/review/ReviewSteps.java b/src/test/java/com/funeat/acceptance/review/ReviewSteps.java index 670d6b22..72d185a7 100644 --- a/src/test/java/com/funeat/acceptance/review/ReviewSteps.java +++ b/src/test/java/com/funeat/acceptance/review/ReviewSteps.java @@ -88,6 +88,15 @@ public class ReviewSteps { .extract(); } + public static ExtractableResponse 리뷰_랭킹_조회_요청(final String loginCookie) { + return given() + .cookie("SESSION", loginCookie) + .when() + .get("/api/ranks/reviews") + .then() + .extract(); + } + public static ExtractableResponse 좋아요를_제일_많이_받은_리뷰_조회_요청(final Long productId) { return given() .when() From 61aec8aa2f5df72463ed51f3cf14cdb35c3b2f68 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Thu, 6 Jun 2024 22:12:52 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refactor:=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20?= =?UTF-8?q?=EC=97=AC=EB=B6=80=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EB=A6=AC?= =?UTF-8?q?=EB=B7=B0=20=EB=9E=AD=ED=82=B9=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=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/funeat/fixture/ReviewFixture.java | 5 ++ .../review/application/ReviewServiceTest.java | 65 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/src/test/java/com/funeat/fixture/ReviewFixture.java b/src/test/java/com/funeat/fixture/ReviewFixture.java index fee2b0b7..b7d2989d 100644 --- a/src/test/java/com/funeat/fixture/ReviewFixture.java +++ b/src/test/java/com/funeat/fixture/ReviewFixture.java @@ -6,6 +6,7 @@ import static com.funeat.fixture.PageFixture.평점_오름차순; import com.funeat.member.domain.Member; +import com.funeat.member.domain.favorite.ReviewFavorite; import com.funeat.product.domain.Product; import com.funeat.review.domain.Review; import com.funeat.review.dto.ReviewCreateRequest; @@ -102,6 +103,10 @@ public class ReviewFixture { return new ReviewFavoriteRequest(favorite); } + public static ReviewFavorite 리뷰_좋아요_생성(final Member member, final Review review, final Boolean favorite) { + return ReviewFavorite.create(member, review, favorite); + } + public static SortingReviewRequest 리뷰정렬요청_좋아요수_내림차순_생성(final Long lastReviewId) { return new SortingReviewRequest(좋아요수_내림차순, lastReviewId); } diff --git a/src/test/java/com/funeat/review/application/ReviewServiceTest.java b/src/test/java/com/funeat/review/application/ReviewServiceTest.java index 0baa6a15..6dbd7f38 100644 --- a/src/test/java/com/funeat/review/application/ReviewServiceTest.java +++ b/src/test/java/com/funeat/review/application/ReviewServiceTest.java @@ -23,6 +23,7 @@ import static com.funeat.fixture.ReviewFixture.리뷰_이미지test4_평점4점_재구매O_생성; import static com.funeat.fixture.ReviewFixture.리뷰_이미지test5_평점5점_재구매X_생성; import static com.funeat.fixture.ReviewFixture.리뷰_이미지없음_평점1점_재구매O_생성; +import static com.funeat.fixture.ReviewFixture.리뷰_좋아요_생성; import static com.funeat.fixture.ReviewFixture.리뷰정렬요청_좋아요수_내림차순_생성; import static com.funeat.fixture.ReviewFixture.리뷰정렬요청_최신순_생성; import static com.funeat.fixture.ReviewFixture.리뷰정렬요청_평점_내림차순_생성; @@ -1345,6 +1346,70 @@ class 리뷰_랭킹_점수에_대한_테스트 { .isEqualTo(expected); } } + + @Nested + class 로그인_여부_응답_테스트 { + + @Test + void 로그인_안한_경우_리뷰_좋아요는_false로_반환한다() { + // given + final var loginId = -1L; + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점4점_생성(category); + 단일_상품_저장(product); + + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var now = LocalDateTime.now(); + final var review = 리뷰_이미지test5_평점5점_재구매X_생성(member, product, 1L, now.minusDays(1L)); + 단일_리뷰_저장(review); + + final var rankingReviewDto = RankingReviewDto.toDto(review, false); + final var rankingReviewDtos = List.of(rankingReviewDto); + final var expected = RankingReviewsResponse.toResponse(rankingReviewDtos); + + // when + final var actual = reviewService.getTopReviews(loginId); + + // then + assertThat(actual).usingRecursiveComparison() + .isEqualTo(expected); + } + + @Test + void 로그인_한_경우_리뷰_좋아요는_로그인한_사용자에_따라_반환한다() { + // given + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + final var loginId = member.getId(); + final var category = 카테고리_간편식사_생성(); + 단일_카테고리_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점4점_생성(category); + 단일_상품_저장(product); + + final var now = LocalDateTime.now(); + final var review = 리뷰_이미지test5_평점5점_재구매X_생성(member, product, 1L, now.minusDays(1L)); + 단일_리뷰_저장(review); + + final var reviewFavorite = 리뷰_좋아요_생성(member, review, true); + 단일_리뷰_좋아요_저장(reviewFavorite); + + final var rankingReviewDto = RankingReviewDto.toDto(review, true); + final var rankingReviewDtos = List.of(rankingReviewDto); + final var expected = RankingReviewsResponse.toResponse(rankingReviewDtos); + + // when + final var actual = reviewService.getTopReviews(loginId); + + // then + assertThat(actual).usingRecursiveComparison() + .isEqualTo(expected); + } + } } private List 태그_아이디_변환(final Tag... tags) { From ac980f92f52dacb0b20f7df48d863fa28f49eccc Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Thu, 6 Jun 2024 22:19:12 +0900 Subject: [PATCH 6/7] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20=EB=9E=AD?= =?UTF-8?q?=ED=82=B9=20=EA=B4=80=EB=A0=A8=20dto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20record=EB=A1=9C=20=ED=83=80=EC=9E=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../funeat/review/dto/RankingReviewDto.java | 94 +++---------------- .../review/dto/RankingReviewsResponse.java | 14 +-- .../review/ReviewAcceptanceTest.java | 4 +- 3 files changed, 19 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/funeat/review/dto/RankingReviewDto.java b/src/main/java/com/funeat/review/dto/RankingReviewDto.java index 5b3e1da3..58805d18 100644 --- a/src/main/java/com/funeat/review/dto/RankingReviewDto.java +++ b/src/main/java/com/funeat/review/dto/RankingReviewDto.java @@ -5,38 +5,20 @@ import com.funeat.tag.dto.TagDto; import java.util.List; -public class RankingReviewDto { - - private final Long id; - private final String userName; - private final String profileImage; - private final Long productId; - private final String productName; - private final String content; - private final String image; - private final Long rating; - private final boolean rebuy; - private final Long favoriteCount; - private final boolean favorite; - private final List tags; - - private RankingReviewDto(final Long id, final String userName, final String profileImage, final Long productId, - final String productName, final String content, final String image, - final Long rating, final boolean rebuy, final Long favoriteCount, final boolean favorite, - final List tags) { - this.id = id; - this.userName = userName; - this.profileImage = profileImage; - this.productId = productId; - this.productName = productName; - this.content = content; - this.image = image; - this.rating = rating; - this.rebuy = rebuy; - this.favoriteCount = favoriteCount; - this.favorite = favorite; - this.tags = tags; - } +public record RankingReviewDto( + Long id, + String userName, + String profileImage, + Long productId, + String productName, + String content, + String image, + Long rating, + boolean rebuy, + Long favoriteCount, + boolean favorite, + List tags +) { public static RankingReviewDto toDto(final Review review, final Boolean favorite) { final List tagDtos = review.getReviewTags().stream() @@ -59,52 +41,4 @@ public static RankingReviewDto toDto(final Review review, final Boolean favorite tagDtos ); } - - public Long getId() { - return id; - } - - public String getUserName() { - return userName; - } - - public String getProfileImage() { - return profileImage; - } - - public Long getProductId() { - return productId; - } - - public String getProductName() { - return productName; - } - - public String getContent() { - return content; - } - - public String getImage() { - return image; - } - - public Long getRating() { - return rating; - } - - public boolean isRebuy() { - return rebuy; - } - - public Long getFavoriteCount() { - return favoriteCount; - } - - public boolean isFavorite() { - return favorite; - } - - public List getTags() { - return tags; - } } diff --git a/src/main/java/com/funeat/review/dto/RankingReviewsResponse.java b/src/main/java/com/funeat/review/dto/RankingReviewsResponse.java index fd2befb0..d3144142 100644 --- a/src/main/java/com/funeat/review/dto/RankingReviewsResponse.java +++ b/src/main/java/com/funeat/review/dto/RankingReviewsResponse.java @@ -2,19 +2,11 @@ import java.util.List; -public class RankingReviewsResponse { - - private final List reviews; - - public RankingReviewsResponse(final List reviews) { - this.reviews = reviews; - } +public record RankingReviewsResponse( + List reviews +) { public static RankingReviewsResponse toResponse(final List reviews) { return new RankingReviewsResponse(reviews); } - - public List getReviews() { - return reviews; - } } diff --git a/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index 64aa29c3..7278553d 100644 --- a/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -878,9 +878,9 @@ class getReviewDetail_실패_테스트 { final var actual = response.jsonPath() .getList("reviews", RankingReviewDto.class); - assertThat(actual).extracting(RankingReviewDto::getId) + assertThat(actual).extracting(RankingReviewDto::id) .containsExactlyElementsOf(reviewIds); - assertThat(actual).extracting(RankingReviewDto::isFavorite) + assertThat(actual).extracting(RankingReviewDto::favorite) .isEqualTo(favorites); } From d97b11c340e6945d66ffbe6c2a24932da144d3f1 Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Fri, 7 Jun 2024 19:52:58 +0900 Subject: [PATCH 7/7] =?UTF-8?q?refactor:=20Boolean=20=ED=83=80=EC=9E=85=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/funeat/review/dto/RankingReviewDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/funeat/review/dto/RankingReviewDto.java b/src/main/java/com/funeat/review/dto/RankingReviewDto.java index 58805d18..a9fd6bcc 100644 --- a/src/main/java/com/funeat/review/dto/RankingReviewDto.java +++ b/src/main/java/com/funeat/review/dto/RankingReviewDto.java @@ -14,9 +14,9 @@ public record RankingReviewDto( String content, String image, Long rating, - boolean rebuy, + Boolean rebuy, Long favoriteCount, - boolean favorite, + Boolean favorite, List tags ) {