diff --git a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java index 34458b5..29403fa 100644 --- a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java +++ b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java @@ -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 List convertPaging(List 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 void validFilterResult(List dataList) { + if (dataList.size() == 0) + throw new EntityNotFoundException(POST_LIST_NOT_FOUND); + } + + private static void validOffsetSize(List dataList, long offset){ + if (dataList.size() <= offset) + throw new InvalidValueException(INVALID_PAGING_SIZE); + } }