From c7734441ab8bc07c73a1ce9591f383c9a802904c Mon Sep 17 00:00:00 2001 From: Go-Jaecheol Date: Wed, 18 Oct 2023 10:48:10 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=B6=A9=EB=8F=8C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/funeat/review/domain/Review.java | 1 + .../review/persistence/ReviewRepository.java | 6 +- .../persistence/ReviewRepositoryTest.java | 64 ++++++++----------- 3 files changed, 31 insertions(+), 40 deletions(-) diff --git a/backend/src/main/java/com/funeat/review/domain/Review.java b/backend/src/main/java/com/funeat/review/domain/Review.java index c97f25c8..9b1a458d 100644 --- a/backend/src/main/java/com/funeat/review/domain/Review.java +++ b/backend/src/main/java/com/funeat/review/domain/Review.java @@ -7,6 +7,7 @@ import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; diff --git a/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java b/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java index 14dc3fd1..69d35018 100644 --- a/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java +++ b/backend/src/main/java/com/funeat/review/persistence/ReviewRepository.java @@ -5,8 +5,6 @@ import com.funeat.member.domain.Member; import com.funeat.product.domain.Product; import com.funeat.review.domain.Review; -import com.funeat.review.dto.SortingReviewDto; -import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import org.springframework.data.domain.Page; @@ -18,8 +16,6 @@ public interface ReviewRepository extends JpaRepository, ReviewCustomRepository { - List findTop3ByOrderByFavoriteCountDescIdDesc(); - Long countByProduct(final Product product); Page findReviewsByMember(final Member findMember, final Pageable pageable); @@ -35,5 +31,7 @@ public interface ReviewRepository extends JpaRepository, ReviewCus + "ORDER BY r.favoriteCount DESC, r.id DESC") List findPopularReviewWithImage(@Param("id") final Long productId, final Pageable pageable); + Optional findTopByProductOrderByFavoriteCountDescIdDesc(final Product product); + List findReviewsByFavoriteCountGreaterThanEqual(final Long favoriteCount); } diff --git a/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java b/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java index a2a44859..46e4645f 100644 --- a/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java +++ b/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java @@ -64,42 +64,7 @@ class countByProduct_성공_테스트 { } @Nested - class findReviewsByProduct_성공_테스트 { - - @Test - void 특정_상품에_대한_좋아요_기준_내림차순으로_정렬한다() { - // given - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - final var member3 = 멤버_멤버3_생성(); - 복수_멤버_저장(member1, member2, member3); - - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); - 단일_상품_저장(product); - - final var review1 = 리뷰_이미지test3_평점3점_재구매O_생성(member1, product, 351L); - final var review2 = 리뷰_이미지test4_평점4점_재구매O_생성(member2, product, 24L); - final var review3 = 리뷰_이미지test3_평점3점_재구매X_생성(member3, product, 130L); - 복수_리뷰_저장(review1, review2, review3); - - final var page = 페이지요청_생성(0, 2, 좋아요수_내림차순); - - final var expected = List.of(review1, review3); - - // when - final var actual = reviewRepository.findReviewsByProduct(page, product).getContent(); - - // then - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - } - - @Nested - class findTopByProductOrderByFavoriteCountDesc_성공_테스트 { + class findPopularReviewWithImage_성공_테스트 { @Test void 리뷰가_존재하지_않으면_빈_값을_반환하다() { @@ -170,6 +135,33 @@ class findTopByProductOrderByFavoriteCountDesc_성공_테스트 { } } + @Nested + class findTopByProductOrderByFavoriteCountDescIdDesc_성공_테스트 { + + @Test + void 좋아요가_가장_많은_리뷰를_반환하다() { + // given + final var category = 카테고리_즉석조리_생성(); + 단일_카테고리_저장(category); + + final var product = 상품_삼각김밥_가격1000원_평점2점_생성(category); + 단일_상품_저장(product); + + final var member = 멤버_멤버1_생성(); + 단일_멤버_저장(member); + + final var review1 = 리뷰_이미지test1_평점1점_재구매O_생성(member, product, 0L); + final var review2 = 리뷰_이미지test3_평점3점_재구매O_생성(member, product, 4L); + 복수_리뷰_저장(review1, review2); + + // when + final var actual = reviewRepository.findTopByProductOrderByFavoriteCountDescIdDesc(product); + + // then + assertThat(actual.get()).isEqualTo(review2); + } + } + @Nested class findReviewsByFavoriteCountGreaterThanEqual_성공_테스트 {