Skip to content

Commit

Permalink
v1.3.4 (#22)
Browse files Browse the repository at this point in the history
v1.3.4
  • Loading branch information
Go-Jaecheol authored Feb 19, 2024
2 parents f96b19e + 4ca009e commit b435aae
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ProductReviewCountDto> productsAndReviewCounts = productRepository.findAllByAverageRatingGreaterThan3(startDateTime, endDateTime);
final List<ProductReviewCountDto> productsAndReviewCounts = productRepository.findAllByAverageRatingGreaterThan3();
final Comparator<ProductReviewCountDto> rankingScoreComparator = Comparator.comparing(
(ProductReviewCountDto it) -> it.getProduct().calculateRankingScore(it.getReviewCount())
).reversed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,10 +14,8 @@ public interface ProductRepository extends BaseRepository<Product, Long> {
+ "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<ProductReviewCountDto> findAllByAverageRatingGreaterThan3(final LocalDateTime startDateTime,
final LocalDateTime endDateTime);
List<ProductReviewCountDto> findAllByAverageRatingGreaterThan3();

@Query("SELECT p FROM Product p "
+ "WHERE p.name LIKE CONCAT('%', :name, '%') "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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์ _์ƒ์„ฑ;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b435aae

Please sign in to comment.