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 @@ -34,7 +34,7 @@ public interface GoalRepository extends JpaRepository<Goal, Integer> {
from Goal g
join fetch g.todos t
where g.user.userId = :userId
and g.goalId = :lastGoalId
and g.goalId > :lastGoalId
and :today between t.startDate and t.endDate
""")
Slice<Goal> findByUserAndHasTodosAfterLastGoalId(@Param("lastGoalId") Integer lastGoalId, @Param("userId") int userId, Pageable pageable, @Param("today") LocalDate today);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.codeit.todo.service.todo.TodoService;
import com.codeit.todo.web.dto.request.todo.*;
import com.codeit.todo.web.dto.response.complete.ReadCompleteResponse;
import com.codeit.todo.web.dto.response.slice.CustomSlice;
import com.codeit.todo.web.dto.response.todo.*;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.PageRequest;
Expand Down Expand Up @@ -106,7 +106,7 @@ public CreateTodoResponse saveTodo(int userId, CreateTodoRequest request) {

@Transactional(readOnly = true)
@Override
public Slice<ReadTodosWithGoalsResponse> findTodoListWithGoals(int userId, @Valid ReadTodoCompleteWithGoalRequest request) {
public Slice<ReadTodosWithGoalsResponse> findTodoListWithGoals(int userId, ReadTodoCompleteWithGoalRequest request) {
int pageSize = request.size();
Pageable pageable = PageRequest.of(0, pageSize);

Expand All @@ -130,7 +130,11 @@ public Slice<ReadTodosWithGoalsResponse> findTodoListWithGoals(int userId, @Vali
})
.toList();

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

return new CustomSlice<>(responses, pageable, goals.hasNext(), nextCursor);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.codeit.todo.web.dto.response.slice;

import lombok.Builder;
import lombok.Getter;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.SliceImpl;

import java.util.List;

@Getter
public class CustomSlice<T> extends SliceImpl<T> {
private final Integer nextCursor;

@Builder
public CustomSlice(List<T> content, Pageable pageable, boolean hasNext, Integer nextCursor) {
super(content, pageable, hasNext);
this.nextCursor = nextCursor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record ReadTodosWithGoalsResponse(
String goalTitle,
String goalColor,
double progress,
int nextCursor,
List<ReadTodosResponse> todos
) {
public static ReadTodosWithGoalsResponse from(Goal goal, List<ReadTodosResponse> responses, double goalProgress) {
Expand Down
Loading