1414import devkor .com .teamcback .domain .vote .repository .VoteTopicRepository ;
1515import devkor .com .teamcback .global .annotation .UpdateScore ;
1616import devkor .com .teamcback .global .exception .exception .GlobalException ;
17+ import devkor .com .teamcback .global .response .CursorPageRes ;
1718import lombok .RequiredArgsConstructor ;
1819import org .springframework .stereotype .Service ;
1920import org .springframework .transaction .annotation .Transactional ;
@@ -101,10 +102,11 @@ else if(!Objects.equals(voteRecord.getVoteOptionId(), voteOption.getId())){ //
101102 * 투표 리스트 조회
102103 */
103104 @ Transactional (readOnly = true )
104- public List <GetVoteRes > getVoteList (VoteStatus status , Long lastVoteId , int size ) {
105+ public CursorPageRes <GetVoteRes > getVoteList (VoteStatus status , Long lastVoteId , int size ) {
106+
105107 List <GetVoteRes > resList = new ArrayList <>();
106108
107- List <Vote > voteList = voteOptionRepository .getVoteByStatusWithPage (status , lastVoteId , size );
109+ List <Vote > voteList = voteOptionRepository .getVoteByStatusWithPage (status , lastVoteId , size + 1 );
108110
109111 for (Vote vote : voteList ) {
110112 // 투표 주제
@@ -119,7 +121,14 @@ public List<GetVoteRes> getVoteList(VoteStatus status, Long lastVoteId, int size
119121 resList .add (new GetVoteRes (vote .getId (), vote .getStatus ().toString (), voteTopic .getId (), voteTopic .getTopic (), place .getId (), place .getName (), voteOptionList ));
120122 }
121123
122- return resList ;
124+ // CursorPageRes 응답
125+ boolean hasNext = voteList .size () > size ;
126+ if (hasNext ) {
127+ resList .remove (size );
128+ }
129+ Long lastCursorId = voteList .isEmpty () ? null : voteList .get (voteList .size () - 1 ).getId ();
130+
131+ return new CursorPageRes <>(resList , hasNext , lastCursorId );
123132 }
124133
125134 /**
0 commit comments