Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 게시물 생성 지난 시간 date 예외 처리 #33

Merged
merged 5 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ private BooleanExpression containTextCondition(String text) {
}

private BooleanExpression validatePostDate() {
return post.endDate.before(LocalDate.now());
return post.endDate.after(LocalDate.now());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -128,14 +129,20 @@ 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) {
if (postRepository.existsByTitle(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static <T> List<T> convertPaging(List<T> 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);
}
}