Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.codeit.todo.web.dto.response.goal.CreateGoalResponse;
import com.codeit.todo.web.dto.response.goal.ReadGoalsResponse;
import com.codeit.todo.web.dto.response.goal.UpdateGoalResponse;
import com.codeit.todo.web.dto.response.slice.CustomSlice;
import com.codeit.todo.web.dto.response.todo.ReadTodosResponse;
import com.codeit.todo.web.dto.response.todo.ReadTodosWithGoalsResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -124,7 +125,11 @@ public Slice<ReadTodosWithGoalsResponse> findAllGoals(int userId, ReadTodoComple

List<ReadTodosWithGoalsResponse> sortedGoalsResponses = sortAllGoals(goalsResponses);

return new SliceImpl<>(sortedGoalsResponses, pageable, goals.hasNext());

Integer nextCursor = goals.hasNext()
? goals.getContent().get(goals.getContent().size() -1).getGoalId()
: null;
return new CustomSlice<>(sortedGoalsResponses, pageable, goals.hasNext(), nextCursor);
}

private Slice<Goal> getGoalsPagination(int userId, ReadTodoCompleteWithGoalRequest request, Pageable pageable){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,4 @@ public List<ReadTodosResponse> makeTodosResponses(List<Todo> todos){
return ReadTodosResponse.from(todo, completeResponses);
}).toList();
}

public Slice<Goal> getGoalsPagination(int userId, ReadTodoCompleteWithGoalRequest request, Pageable pageable){
Slice<Goal> goals;
if (Objects.isNull(request.lastGoalId()) || request.lastGoalId() <= 0) {
goals = goalRepository.findByUser_UserId(userId, pageable);
} else {
goals = goalRepository.findByGoalIdAndUser_UserId(request.lastGoalId(), userId, pageable);
}

return goals;
}
}
Loading