Skip to content

Commit

Permalink
feat: category 개수 7개 제약 조건 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
baebae02 committed Oct 31, 2023
1 parent f234281 commit a5f1fcc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/uspray/uspray/exception/ErrorStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ErrorStatus {
INVALID_TOKEN_INFO_EXCEPTION(HttpStatus.BAD_REQUEST, "토큰 혹은 만료시간 설정이 잘못되었습니다."),
SENDER_RECEIVER_SAME_EXCEPTION(HttpStatus.BAD_REQUEST, "자신에게는 기도제목을 공유할 수 없습니다."),
CATEGORY_ALREADY_EXIST_EXCEPTION(HttpStatus.BAD_REQUEST, "이미 존재하는 카테고리입니다."),
CATEGORY_LIMIT_EXCEPTION(HttpStatus.BAD_REQUEST, "카테고리는 최대 7개까지 생성 가능합니다."),

/*
* 401 UNAUTHORIZED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface CategoryRepository extends JpaRepository<Category, Long> {
Category getCategoryById(Long categoryId);

boolean existsCategoryByNameAndMember(String name, Member member);

int countCategoryByMember(Member member);
}
4 changes: 4 additions & 0 deletions src/main/java/com/uspray/uspray/service/CategoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public CategoryResponseDto createCategory(String username,
throw new NotFoundException(ErrorStatus.CATEGORY_ALREADY_EXIST_EXCEPTION,
ErrorStatus.CATEGORY_ALREADY_EXIST_EXCEPTION.getMessage());
}
if (categoryRepository.countCategoryByMember(member) > 7) {
throw new NotFoundException(ErrorStatus.CATEGORY_LIMIT_EXCEPTION,
ErrorStatus.CATEGORY_LIMIT_EXCEPTION.getMessage());
}
Category category = categoryRequestDto.toEntity(member);
categoryRepository.save(category);
return CategoryResponseDto.of(category);
Expand Down

0 comments on commit a5f1fcc

Please sign in to comment.