Skip to content

Commit

Permalink
#322 reafctor: 와인 리뷰 조회 페이징 기능 추가 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongyun1206 committed Jan 13, 2025
1 parent ec25f5f commit 4171dfb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public List<TastingNote> findTastingNoteBySortAndUsername(TastingNoteWineSort wi
.fetch();
}


@Override
public List<TastingNote> findAllTastingNoteBy(Long wineId, SortType sort, Pageable pageable) {
return queryFactory.selectFrom(tastingNote)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,32 @@ void findTastingNoteByWineIdLowestRating() {
);
}

@DisplayName("와인 아이디로 테이스팅 노트를 별점 높은순 정렬 조회한다.(페이징)")
@Test
void findTastingNoteByWineIdHighestRatingWithPaging() {
// given
Member member = memberRepository.save(createMember("user"));
Wine wine = wineRepository.save(createWine("레드 와인"));

TastingNote tastingNote1 = createTastingNote(member, wine, 50, 30, 20, 40, 30, 4.0f, "Review 1");
TastingNote tastingNote2 = createTastingNote(member, wine, 60, 35, 30, 40, 0, 3.0f, "Review 2");
TastingNote tastingNote3 = createTastingNote(member, wine, 40, 40, 40, 40, 60, 5.0f, "Review 3");

tastingNoteRepository.saveAll(List.of(tastingNote1, tastingNote2, tastingNote3));

Pageable pageable = PageRequest.of(0, 2);
// when
List<TastingNote> tastingNotes = tastingNoteRepository.findAllTastingNoteBy(wine.getId(), SortType.HIGH_RATING, pageable);

// then
assertThat(tastingNotes).hasSize(2)
.extracting("rating", "review")
.containsExactly(
tuple(5.0f, "Review 3"),
tuple(4.0f, "Review 1")
);
}

private TastingNote createTastingNote(Member member, Wine wine,
int sugarContent, int acidity, int tannin, int body, int alcohol,
float rating, String review) {
Expand Down

0 comments on commit 4171dfb

Please sign in to comment.