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
8 changes: 7 additions & 1 deletion src/main/java/com/codeit/todo/repository/GoalRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public interface GoalRepository extends JpaRepository<Goal, Integer> {

Slice<Goal> findByUser_UserId(@Param("userId") int userId, Pageable pageable);

Slice<Goal> findByGoalIdAndUser_UserId(@Param("lastGoalId") Integer lastGoalId, @Param("userId") int userId, Pageable pageable);
@Query(
"SELECT g FROM Goal g " +
"WHERE g.user.userId = :userId " +
"AND g.goalId > :lastGoalId "
)
Slice<Goal> findByGoalIdAndUser_UserIdAndGoalIdGreaterThan(@Param("userId") int userId, @Param("lastGoalId")int lastGoalId, Pageable pageable);

@Query("""
select g
Expand All @@ -40,4 +45,5 @@ public interface GoalRepository extends JpaRepository<Goal, Integer> {
Slice<Goal> findByUserAndHasTodosAfterLastGoalId(@Param("lastGoalId") Integer lastGoalId, @Param("userId") int userId, Pageable pageable, @Param("today") LocalDate today);

List<Goal> findByGoalTitleContains(@Param("keyword") String keyword);

}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ private Slice<Goal> getGoalsPagination(int userId, ReadTodoCompleteWithGoalReque
if (Objects.isNull(request.lastGoalId()) || request.lastGoalId() <= 0) {
goals = goalRepository.findByUser_UserId(userId, pageable);
} else {
goals = goalRepository.findByGoalIdAndUser_UserId(request.lastGoalId(), userId, pageable);
int lastGoalId = request.lastGoalId();
goals = goalRepository.findByGoalIdAndUser_UserIdAndGoalIdGreaterThan(userId, lastGoalId, pageable);
}
return goals;
}
Expand Down
Loading