Skip to content

Commit

Permalink
fix: 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
Go-Jaecheol committed Oct 18, 2023
1 parent 6d236ed commit c773444
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 40 deletions.
1 change: 1 addition & 0 deletions backend/src/main/java/com/funeat/review/domain/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,8 +16,6 @@

public interface ReviewRepository extends JpaRepository<Review, Long>, ReviewCustomRepository {

List<Review> findTop3ByOrderByFavoriteCountDescIdDesc();

Long countByProduct(final Product product);

Page<Review> findReviewsByMember(final Member findMember, final Pageable pageable);
Expand All @@ -35,5 +31,7 @@ public interface ReviewRepository extends JpaRepository<Review, Long>, ReviewCus
+ "ORDER BY r.favoriteCount DESC, r.id DESC")
List<Review> findPopularReviewWithImage(@Param("id") final Long productId, final Pageable pageable);

Optional<Review> findTopByProductOrderByFavoriteCountDescIdDesc(final Product product);

List<Review> findReviewsByFavoriteCountGreaterThanEqual(final Long favoriteCount);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 리뷰가_존재하지_않으면_빈_값을_반환하다() {
Expand Down Expand Up @@ -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_성공_테스트 {

Expand Down

0 comments on commit c773444

Please sign in to comment.