diff --git a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java index 1fa1e3d..08742b9 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java +++ b/src/main/java/org/gachon/checkmate/domain/post/repository/PostCustomRepositoryImpl.java @@ -121,6 +121,6 @@ private BooleanExpression containTextCondition(String text) { } private BooleanExpression validatePostDate() { - return post.endDate.before(LocalDate.now()); + return post.endDate.after(LocalDate.now()); } } diff --git a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java index 15f8263..68494a4 100644 --- a/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java +++ b/src/main/java/org/gachon/checkmate/domain/post/service/PostService.java @@ -47,6 +47,7 @@ public class PostService { public void createPost(Long userId, PostCreateRequestDto requestDto) { validateDuplicateTitle(requestDto.title()); + validateAvailableEndDate(requestDto.endDate()); User user = getUserOrThrow(userId); Post post = createPostAndSave(requestDto, user); createPostCheckListAndSave(requestDto.checkList(), post); @@ -128,7 +129,7 @@ private int getRateForFrequencyElement(String firstEnumCode, String secondEnumCo } private int getRemainDate(LocalDate endDate) { - return (int) endDate.until(LocalDate.now(), ChronoUnit.DAYS); + return (int) LocalDate.now().until(endDate, ChronoUnit.DAYS); } private void validateDuplicateTitle(String title) { @@ -136,6 +137,12 @@ private void validateDuplicateTitle(String title) { throw new InvalidValueException(INVALID_POST_TITLE); } + private void validateAvailableEndDate(LocalDate endDate) { + LocalDate now = LocalDate.now(); + if (endDate.isBefore(now)) + throw new InvalidValueException(INVALID_POST_DATE); + } + private Post createPostAndSave(PostCreateRequestDto postCreateRequestDto, User user) { Post post = Post.createPost(postCreateRequestDto, user); postRepository.save(post); diff --git a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java index 02fdbe8..c4ea46c 100644 --- a/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java +++ b/src/main/java/org/gachon/checkmate/global/error/ErrorCode.java @@ -16,6 +16,7 @@ public enum ErrorCode { INVALID_PAGING_SIZE(HttpStatus.BAD_REQUEST, "잘못된 Paging 크기입니다."), INVALID_PASSWORD(HttpStatus.BAD_REQUEST, "비밀번호는 8~20자 대소문자 영문, 숫자, 특수문자의 조합이어야 합니다."), INVALID_POST_TITLE(HttpStatus.BAD_REQUEST, "이미 존재하는 게시물입니다."), + INVALID_POST_DATE(HttpStatus.BAD_REQUEST, "마감시간이 지난 게시물입니다."), /** * 401 Unauthorized 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 81fa48e..4b34d06 100644 --- a/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java +++ b/src/main/java/org/gachon/checkmate/global/utils/PagingUtils.java @@ -14,7 +14,7 @@ public static List convertPaging(List dataList, long page, int size) { if (dataList.size() <= page * size) throw new InvalidValueException(INVALID_PAGING_SIZE); int startIndex = (int) page * size; - int endIndex = Math.min(dataList.size(), (int) page * (size + 1)); + int endIndex = Math.min(dataList.size(), (int) (page + 1) * size); return dataList.subList(startIndex, endIndex); } }