@@ -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