Skip to content

Commit

Permalink
fix: 투데이/백로그 빈 문자열로 응답 통일(유혀하지 않은 페이지 예외 없앰)
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonjookang committed Oct 21, 2024
1 parent 3fcef0c commit 2d213ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
21 changes: 7 additions & 14 deletions src/main/java/server/poptato/todo/application/TodoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,15 @@ public TodayListResponseDto getTodayList(long userId, int page, int size, LocalD
userId, Type.TODAY, todayDate, TodayStatus.COMPLETED);
todays.addAll(completedTodos);

// 전체 리스트에서 페이징
int start = (page) * size;
int end = Math.min(start + size, todays.size());
List<Todo> todaySubList;
int totalPageCount;
if (start >= end) todaySubList = new ArrayList<>();
else todaySubList = todays.subList(start, end);

int totalPageCount = (int) Math.ceil((double) todays.size() / size);

if(todays.size()==0) {
totalPageCount = 0;
todaySubList = new ArrayList<>();
}
else{
// 전체 리스트에서 페이징
int start = (page) * size;
int end = Math.min(start + size, todays.size());
if (start >= end) throw new TodoException(TodoExceptionErrorCode.INVALID_PAGE);

todaySubList = todays.subList(start, end);
totalPageCount = (int) Math.ceil((double) todays.size() / size);
}
return TodayListResponseDto.builder()
.date(todayDate)
.todays(todaySubList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@ 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 & 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();
}

@DisplayName("투데이_데이터가 없는 경우 null을 반환한다.")
@DisplayName("투데이_데이터가 없는 경우 빈 리스트를 반환한다.")
@Test
void 투데이_데이터_수_0개_응답(){
//given
Expand All @@ -85,7 +85,7 @@ class TodoServiceTest {
assertThat(todayList.getTotalPageCount()).isEqualTo(0);
}

@DisplayName("백로그_데이터가 없는 경우 null을 반환한다.")
@DisplayName("백로그_데이터가 없는 경우 빈 리스트를 반환한다.")
@Test
void 백로그_데이터_수_0개_응답(){
//given
Expand Down

0 comments on commit 2d213ef

Please sign in to comment.