Skip to content

Commit

Permalink
Merge pull request #33 from Domitory-CheckMate/feature/32-post
Browse files Browse the repository at this point in the history
  • Loading branch information
RyuKwanKon committed Jan 11, 2024
2 parents 604edb9 + 61ec8b6 commit 56ec01a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
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);
}
}

0 comments on commit 56ec01a

Please sign in to comment.