Skip to content

Commit

Permalink
Merge pull request #76 from Kusitms-POPTATO-DEV/fix/backlog-list
Browse files Browse the repository at this point in the history
Fix: backlog 리스트 조회 수정
  • Loading branch information
yeonjookang authored Nov 3, 2024
2 parents ae180e8 + 1d873fd commit 852398d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,49 @@

public interface TodoRepository {
void deleteAllByUserId(Long userId);

List<Todo> findByUserIdAndTypeAndTodayDateAndTodayStatusOrderByTodayOrderDesc(
Long userId, Type type, LocalDate todayDate, TodayStatus todayStatus);

List<Todo> findByUserIdAndTypeAndTodayDateAndTodayStatusOrderByCompletedDateTimeAsc(
Long userId, Type type, LocalDate todayDate, TodayStatus todayStatus);

Optional<Todo> findById(Long todoId);

void delete(Todo todo);

Page<Todo> findByUserIdAndCompletedStatusAndDifferentTodayDate(Long userId, TodayStatus todayStatus, LocalDate today, Pageable pageable);

Todo save(Todo todo);
Page<Todo> findByUserIdAndTypeInAndTodayStatusNotInOrderByBacklogOrderDesc(Long userId, List<Type> types, List<TodayStatus> excludedStatuses, Pageable pageable);

Page<Todo> findBacklogsByUserId(Long userId, List<Type> types, List<TodayStatus> statuses, Pageable pageable);

Integer findMaxBacklogOrderByUserIdOrZero(Long userId);

Integer findMaxTodayOrderByUserIdOrZero(Long userId);

Integer findMinTodayOrderByUserIdOrZero(Long userId);

int findMaxBacklogOrderByIdIn(List<Long> ids);

int findMaxTodayOrderByIdIn(List<Long> ids);

Page<Todo> findByUserIdAndTypeAndTodayStatus(Long userId, Type type, TodayStatus todayStatus, Pageable pageable);

List<Todo> findByTypeAndTodayStatus(Type today, TodayStatus incomplete);

Integer findMinBacklogOrderByUserIdOrZero(Long userId);

default List<Todo> findIncompleteTodays(Long userId, Type type, LocalDate todayDate, TodayStatus todayStatus){
default List<Todo> findIncompleteTodays(Long userId, Type type, LocalDate todayDate, TodayStatus todayStatus) {
return findByUserIdAndTypeAndTodayDateAndTodayStatusOrderByTodayOrderDesc(
userId, type, todayDate, todayStatus);
}
default List<Todo> findCompletedTodays(Long userId, Type type, LocalDate todayDate, TodayStatus todayStatus){

default List<Todo> findCompletedTodays(Long userId, Type type, LocalDate todayDate, TodayStatus todayStatus) {
return findByUserIdAndTypeAndTodayDateAndTodayStatusOrderByCompletedDateTimeAsc(
userId, type, todayDate, todayStatus);
}

default Page<Todo> findBacklogsByUserId(Long userId, List<Type> types, List<TodayStatus> statuses, Pageable pageable){
return findByUserIdAndTypeInAndTodayStatusNotInOrderByBacklogOrderDesc(
userId, types, statuses, pageable);
}
default Page<Todo> findHistories(Long userId, LocalDate today, Pageable pageable) {
return findByUserIdAndCompletedStatusAndDifferentTodayDate(userId, TodayStatus.COMPLETED, today, pageable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import server.poptato.todo.domain.entity.Todo;
import server.poptato.todo.domain.repository.TodoRepository;
import server.poptato.todo.domain.value.TodayStatus;
import server.poptato.todo.domain.value.Type;

import java.time.LocalDate;
import java.util.List;

public interface JpaTodoRepository extends TodoRepository, JpaRepository<Todo,Long> {
@Query("SELECT t FROM Todo t WHERE t.userId = :userId AND t.completedDateTime IS NOT NULL")
Page<Todo> findByUserIdAndCompletedDateTimeIsNotNull(Long userId, Pageable pageable);
@Query("SELECT COALESCE(MAX(t.backlogOrder), 0) FROM Todo t WHERE t.userId = :userId AND t.backlogOrder IS NOT NULL")
Integer findMaxBacklogOrderByUserIdOrZero(Long userId);
@Query("SELECT COALESCE(MAX(t.todayOrder), 0) FROM Todo t WHERE t.userId = :userId AND t.todayOrder IS NOT NULL")
Expand All @@ -34,4 +33,11 @@ Page<Todo> findByUserIdAndCompletedStatusAndDifferentTodayDate(
@Param("todayDate") LocalDate todayDate,
Pageable pageable
);
@Query("SELECT t FROM Todo t WHERE t.userId = :userId AND (t.type IN :types AND (t.todayStatus NOT IN :statuses OR t.todayStatus IS NULL)) " +
"ORDER BY t.backlogOrder DESC")
Page<Todo> findBacklogsByUserId(
@Param("userId") Long userId,
@Param("types") List<Type> types,
@Param("statuses") List<TodayStatus> statuses,
Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ void getBacklogList_EmptyToday_Success() {

//when
BacklogListResponseDto backlogList = todoBacklogService.getBacklogList(userId, page, size);
for(BacklogResponseDto todo : backlogList.getBacklogs()){
Long todoId = todo.getTodoId();
System.out.println(todoId);
}

//then
assertThat(backlogList.getBacklogs()).isEmpty();
assertThat(backlogList.getBacklogs().size()).isEqualTo(0);
assertThat(backlogList.getTotalPageCount()).isEqualTo(0);
}

Expand Down Expand Up @@ -111,7 +115,7 @@ void getYesterdays_Success() {
// given
Long userId = 1L;
int page = 0;
int size = 5; // 한번에 5개의 todo 가져오기
int size = 5;

// when
PaginatedYesterdayResponseDto result = todoBacklogService.getYesterdays(userId, page, size);
Expand Down

0 comments on commit 852398d

Please sign in to comment.