Skip to content

Commit

Permalink
[fix] #55 필터에 해당하는 게시글이 없을 경우 예외 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuKwanKon committed Jan 21, 2024
1 parent 6a1907b commit a68e2ad
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,31 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.gachon.checkmate.global.error.exception.EntityNotFoundException;
import org.gachon.checkmate.global.error.exception.InvalidValueException;

import java.util.List;

import static org.gachon.checkmate.global.error.ErrorCode.INVALID_PAGING_SIZE;
import static org.gachon.checkmate.global.error.ErrorCode.POST_LIST_NOT_FOUND;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PagingUtils {
public static <T> List<T> convertPaging(List<T> dataList, long offset, int size) {
if (dataList.size() <= offset)
throw new InvalidValueException(INVALID_PAGING_SIZE);
validFilterResult(dataList);
validOffsetSize(dataList, offset);
int startIndex = (int) offset;
int endIndex = Math.min(dataList.size(), startIndex + size);
return dataList.subList(startIndex, endIndex);
}

private static <T> void validFilterResult(List<T> dataList) {
if (dataList.size() == 0)
throw new EntityNotFoundException(POST_LIST_NOT_FOUND);
}

private static <T> void validOffsetSize(List<T> dataList, long offset){
if (dataList.size() <= offset)
throw new InvalidValueException(INVALID_PAGING_SIZE);
}
}

0 comments on commit a68e2ad

Please sign in to comment.