Skip to content

Commit

Permalink
Merge pull request #60 from Kusitms-POPTATO-DEV/fix/todo-list-null
Browse files Browse the repository at this point in the history
Fix: 투데이/백로그 조회 시 데이터가 없을 경우 예외가 아닌 빈 리스트 반환으로 수정
  • Loading branch information
yeonjookang authored Oct 21, 2024
2 parents 85fc364 + 2d213ef commit e411891
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ public TodayListResponseDto getTodayList(long userId, int page, int size, LocalD
// 전체 리스트에서 페이징
int start = (page) * size;
int end = Math.min(start + size, todays.size());
if (start >= end) throw new TodoException(TodoExceptionErrorCode.INVALID_PAGE);
List<Todo> todaySubList;
if (start >= end) todaySubList = new ArrayList<>();
else todaySubList = todays.subList(start, end);

List<Todo> todaySubList = todays.subList(start, end);
int totalPageCount = (int) Math.ceil((double) todays.size() / size);

return TodayListResponseDto.builder()
Expand Down
41 changes: 35 additions & 6 deletions src/test/java/server/poptato/todo/application/TodoServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,47 @@ class TodoServiceTest {
assertThat(todoService.getTodayList(userId,page,size,todayDate).getTodays().size()).isEqualTo(size);
}

@DisplayName("유효하지 않는 페이지 수일 경우 예외가 발생한다.")
@DisplayName("유효하지 않는 페이지 수일 경우 빈 리스트를 반환한다.")
@Test
void 유효하지_않은_페이지_수_예외(){
void 유효하지_않은_페이지_수_응답(){
//given
Long userId = 1L;
int page = 2;
int size = 8;
LocalDate todayDate = LocalDate.of(2024,10,16);
//when
TodayListResponseDto todayList = todoService.getTodayList(userId, page, size, todayDate);
//then
assertThat(todayList.getTodays()).isEmpty();
}

@DisplayName("투데이_데이터가 없는 경우 빈 리스트를 반환한다.")
@Test
void 투데이_데이터_수_0개_응답(){
//given
Long userId = 50L;
int page = 0;
int size = 8;
LocalDate todayDate = LocalDate.now();
//when & then
assertThatThrownBy(()-> todoService.getTodayList(userId,page,size,todayDate))
.isInstanceOf(TodoException.class)
.hasMessage(TodoExceptionErrorCode.INVALID_PAGE.getMessage());
//when
TodayListResponseDto todayList = todoService.getTodayList(userId, page, size, todayDate);
//then
assertThat(todayList.getTodays()).isEmpty();
assertThat(todayList.getTotalPageCount()).isEqualTo(0);
}

@DisplayName("백로그_데이터가 없는 경우 빈 리스트를 반환한다.")
@Test
void 백로그_데이터_수_0개_응답(){
//given
Long userId = 50L;
int page = 0;
int size = 8;
//when
BacklogListResponseDto backlogList = todoService.getBacklogList(userId, page, size);
//then
assertThat(backlogList.getBacklogs()).isEmpty();
assertThat(backlogList.getTotalPageCount()).isEqualTo(0);
}

@DisplayName("투데이 목록 조회 시, 미달성 투데이가 먼저 조회되고, 그 다음 달성 투데이가 조회된다.")
Expand Down

0 comments on commit e411891

Please sign in to comment.