diff --git a/src/main/java/com/funeat/product/application/ProductService.java b/src/main/java/com/funeat/product/application/ProductService.java index 74fd2032..84859fc5 100644 --- a/src/main/java/com/funeat/product/application/ProductService.java +++ b/src/main/java/com/funeat/product/application/ProductService.java @@ -32,7 +32,6 @@ import com.funeat.review.persistence.ReviewRepository; import com.funeat.review.persistence.ReviewTagRepository; import com.funeat.tag.domain.Tag; -import java.time.LocalDateTime; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -119,9 +118,7 @@ public ProductResponse findProductDetail(final Long productId) { } public RankingProductsResponse getTop3Products() { - final LocalDateTime endDateTime = LocalDateTime.now(); - final LocalDateTime startDateTime = endDateTime.minusWeeks(2L); - final List productsAndReviewCounts = productRepository.findAllByAverageRatingGreaterThan3(startDateTime, endDateTime); + final List productsAndReviewCounts = productRepository.findAllByAverageRatingGreaterThan3(); final Comparator rankingScoreComparator = Comparator.comparing( (ProductReviewCountDto it) -> it.getProduct().calculateRankingScore(it.getReviewCount()) ).reversed(); diff --git a/src/main/java/com/funeat/product/persistence/ProductRepository.java b/src/main/java/com/funeat/product/persistence/ProductRepository.java index 1982539f..7d4e2161 100644 --- a/src/main/java/com/funeat/product/persistence/ProductRepository.java +++ b/src/main/java/com/funeat/product/persistence/ProductRepository.java @@ -3,9 +3,7 @@ import com.funeat.common.repository.BaseRepository; import com.funeat.product.domain.Product; import com.funeat.product.dto.ProductReviewCountDto; -import java.time.LocalDateTime; import java.util.List; -import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; @@ -16,10 +14,8 @@ public interface ProductRepository extends BaseRepository { + "FROM Product p " + "LEFT JOIN Review r ON r.product.id = p.id " + "WHERE p.averageRating > 3.0 " - + "AND r.createdAt BETWEEN :startDateTime AND :endDateTime " + "GROUP BY p.id") - List findAllByAverageRatingGreaterThan3(final LocalDateTime startDateTime, - final LocalDateTime endDateTime); + List findAllByAverageRatingGreaterThan3(); @Query("SELECT p FROM Product p " + "WHERE p.name LIKE CONCAT('%', :name, '%') " diff --git a/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java b/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java index b8e5cfee..9cdced56 100644 --- a/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java +++ b/src/test/java/com/funeat/product/persistence/ProductRepositoryTest.java @@ -4,7 +4,6 @@ import static com.funeat.fixture.MemberFixture.멤버_멤버1_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버2_생성; import static com.funeat.fixture.MemberFixture.멤버_멤버3_생성; -import static com.funeat.fixture.PageFixture.페이지요청_기본_생성; import static com.funeat.fixture.ProductFixture.상품_망고빙수_가격5000원_평점4점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점4점_생성; @@ -20,7 +19,6 @@ import com.funeat.common.RepositoryTest; import com.funeat.product.dto.ProductReviewCountDto; import java.time.LocalDateTime; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -62,39 +60,7 @@ class findAllByAverageRatingGreaterThan3_성공_테스트 { final var expected = List.of(productReviewCountDto1, productReviewCountDto2); // when - final var startDateTime = LocalDateTime.now().minusWeeks(2L); - final var endDateTime = LocalDateTime.now(); - final var actual = productRepository.findAllByAverageRatingGreaterThan3(startDateTime, endDateTime); - - // then - assertThat(actual).usingRecursiveComparison() - .isEqualTo(expected); - } - - @Test - void 기간_안에_리뷰가_존재하는_상품이_없으면_빈_리스트를_반환한다() { - // given - final var category = 카테고리_간편식사_생성(); - 단일_카테고리_저장(category); - - final var product1 = 상품_삼각김밥_가격1000원_평점3점_생성(category); - final var product2 = 상품_삼각김밥_가격2000원_평점4점_생성(category); - 복수_상품_저장(product1, product2); - - final var member1 = 멤버_멤버1_생성(); - final var member2 = 멤버_멤버2_생성(); - 복수_멤버_저장(member1, member2); - - final var review1 = 리뷰_이미지test5_평점5점_재구매X_생성(member1, product1, 0L, LocalDateTime.now().minusDays(15L)); - final var review2 = 리뷰_이미지test5_평점5점_재구매X_생성(member2, product2, 0L, LocalDateTime.now().minusWeeks(3L)); - 복수_리뷰_저장(review1, review2); - - final var expected = Collections.emptyList(); - - // when - final var startDateTime = LocalDateTime.now().minusWeeks(2L); - final var endDateTime = LocalDateTime.now(); - final var actual = productRepository.findAllByAverageRatingGreaterThan3(startDateTime, endDateTime); + final var actual = productRepository.findAllByAverageRatingGreaterThan3(); // then assertThat(actual).usingRecursiveComparison()