Skip to content
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 @@ -49,6 +49,11 @@ public List<Category> findSubCategory() {
.toList();
}

@Override
public boolean existsByNameOrCode(String name, String code) {
return categoryRepository.existsByNameOrCode(name, code);
}

@Override
public void save(final Category category) {
categoryRepository.save(categoryPersistenceMapper.toEntity(category));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface CategoryRepository extends JpaRepository<CategoryEntity, Long>
List<CategoryEntity> findByIsDeletedFalse();
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNull();
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNotNull();

boolean existsByNameOrCode(String name, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface LoadCategoryPort {
List<Category> findAll();
List<Category> findMainCategory();
List<Category> findSubCategory();

boolean existsByNameOrCode(String name, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Optional;

import static clap.server.exception.code.MemberErrorCode.ACTIVE_MEMBER_NOT_FOUND;
import static clap.server.exception.code.TaskErrorCode.CATEGORY_DUPLICATE;
import static clap.server.exception.code.TaskErrorCode.CATEGORY_NOT_FOUND;

@ApplicationService
Expand All @@ -28,6 +29,7 @@ public class AddCategoryService implements AddMainCategoryUsecase, AddSubCategor
@Transactional
public void addMainCategory(Long adminId, String code, String name) {
Optional<Member> activeMember = loadMemberPort.findActiveMemberById(adminId);
if (loadCategoryPort.existsByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category mainCategory = Category.createMainCategory(
activeMember.orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)),
code, name);
Expand All @@ -39,7 +41,7 @@ public void addMainCategory(Long adminId, String code, String name) {
public void addSubCategory(Long adminId, Long mainCategoryId, String code, String name, String descriptionExample) {
Optional<Member> activeMember = loadMemberPort.findActiveMemberById(adminId);
Optional<Category> mainCategory = loadCategoryPort.findById(mainCategoryId);

if (loadCategoryPort.existsByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category subCategory = Category.createSubCategory(
activeMember.orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)),
mainCategory.orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND)),
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/clap/server/exception/code/TaskErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public enum TaskErrorCode implements BaseErrorCode {
NOT_A_REVIEWER(HttpStatus.FORBIDDEN, "TASK_009", "작업 승인 및 수정 권한이 없습니다."),
NOT_A_REQUESTER(HttpStatus.FORBIDDEN, "TASK_010", "작업 수정 및 취소 권한이 없습니다."),
TASK_STATUS_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "TASK_011", "변경할 수 없는 작업 상태입니다. 다른 API를 사용해주세요"),
FILE_COUNT_EXCEEDED(HttpStatus.BAD_REQUEST, "TASK_012", "파일은 5개 이상 첨부 가능합니다.")
FILE_COUNT_EXCEEDED(HttpStatus.BAD_REQUEST, "TASK_012", "파일은 5개 이상 첨부 가능합니다."),
CATEGORY_DUPLICATE(HttpStatus.BAD_REQUEST, "TASK_013", "카테고리 이름 또는 코드는 중복될 수 없습니다.")
;

private final HttpStatus httpStatus;
Expand Down
Loading