Skip to content

Commit 2e77586

Browse files
authored
[fix]칵테일 다건조회 무한스크롤 버그 수정 (#268)
* fix : bugs of testCase, init data * fix : bug * fix : parameter name * fix: bug
1 parent 9e302a8 commit 2e77586

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/main/java/com/back/domain/cocktail/service/CocktailService.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,23 @@ public List<CocktailSummaryResponseDto> getCocktails(Long lastValue, Long lastId
4343
Pageable pageable = PageRequest.of(0, fetchSize);
4444
List<Cocktail> cocktails;
4545

46+
Long cursor = (lastValue != null) ? lastValue : lastId;
47+
4648
switch (sortBy != null ? sortBy.toLowerCase() : "") {
4749
case "keeps":
48-
cocktails = (lastValue == null)
50+
cocktails = (cursor == null)
4951
? cocktailRepository.findAllOrderByKeepCountDesc(pageable)
50-
: cocktailRepository.findByKeepCountLessThanOrderByKeepCountDesc(lastValue, lastId, pageable);
52+
: cocktailRepository.findByKeepCountLessThanOrderByKeepCountDesc(cursor, lastId, pageable);
5153
break;
5254
case "comments":
53-
cocktails = (lastValue == null)
55+
cocktails = (cursor == null)
5456
? cocktailRepository.findAllOrderByCommentsCountDesc(pageable)
55-
: cocktailRepository.findByCommentsCountLessThanOrderByCommentsCountDesc(lastValue, lastId, pageable);
57+
: cocktailRepository.findByCommentsCountLessThanOrderByCommentsCountDesc(cursor, lastId, pageable);
5658
break;
5759
default:
58-
cocktails = (lastValue == null)
60+
cocktails = (cursor == null)
5961
? cocktailRepository.findAllByOrderByIdDesc(pageable)
60-
: cocktailRepository.findByIdLessThanOrderByIdDesc(lastValue, pageable);
62+
: cocktailRepository.findByIdLessThanOrderByIdDesc(cursor, pageable);
6163
break;
6264
}
6365

0 commit comments

Comments
 (0)