Skip to content

Commit fe11ced

Browse files
CLAP-343 카테고리 고유코드 및 제목 중복 가능한 문제 수정
* CLAP-343 fix: 카테고리 고유코드 및 제목 중복 가능한 문제 수정 <footer> - #443 * CLAP-343 fix: 카테고리 고유코드 및 제목 중복 가능한 문제 수정 <footer> - #443
1 parent f01e1bc commit fe11ced

File tree

5 files changed

+14
-2
lines changed

5 files changed

+14
-2
lines changed

src/main/java/clap/server/adapter/outbound/persistense/CategoryPersistenceAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public List<Category> findSubCategory() {
4949
.toList();
5050
}
5151

52+
@Override
53+
public boolean existsByNameOrCode(String name, String code) {
54+
return categoryRepository.existsByNameOrCode(name, code);
55+
}
56+
5257
@Override
5358
public void save(final Category category) {
5459
categoryRepository.save(categoryPersistenceMapper.toEntity(category));

src/main/java/clap/server/adapter/outbound/persistense/repository/task/CategoryRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface CategoryRepository extends JpaRepository<CategoryEntity, Long>
1111
List<CategoryEntity> findByIsDeletedFalse();
1212
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNull();
1313
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNotNull();
14+
15+
boolean existsByNameOrCode(String name, String code);
1416
}

src/main/java/clap/server/application/port/outbound/task/LoadCategoryPort.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ public interface LoadCategoryPort {
1111
List<Category> findAll();
1212
List<Category> findMainCategory();
1313
List<Category> findSubCategory();
14+
15+
boolean existsByNameOrCode(String name, String code);
1416
}

src/main/java/clap/server/application/service/admin/AddCategoryService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Optional;
1616

1717
import static clap.server.exception.code.MemberErrorCode.ACTIVE_MEMBER_NOT_FOUND;
18+
import static clap.server.exception.code.TaskErrorCode.CATEGORY_DUPLICATE;
1819
import static clap.server.exception.code.TaskErrorCode.CATEGORY_NOT_FOUND;
1920

2021
@ApplicationService
@@ -28,6 +29,7 @@ public class AddCategoryService implements AddMainCategoryUsecase, AddSubCategor
2829
@Transactional
2930
public void addMainCategory(Long adminId, String code, String name) {
3031
Optional<Member> activeMember = loadMemberPort.findActiveMemberById(adminId);
32+
if (loadCategoryPort.existsByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
3133
Category mainCategory = Category.createMainCategory(
3234
activeMember.orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)),
3335
code, name);
@@ -39,7 +41,7 @@ public void addMainCategory(Long adminId, String code, String name) {
3941
public void addSubCategory(Long adminId, Long mainCategoryId, String code, String name, String descriptionExample) {
4042
Optional<Member> activeMember = loadMemberPort.findActiveMemberById(adminId);
4143
Optional<Category> mainCategory = loadCategoryPort.findById(mainCategoryId);
42-
44+
if (loadCategoryPort.existsByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
4345
Category subCategory = Category.createSubCategory(
4446
activeMember.orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)),
4547
mainCategory.orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND)),

src/main/java/clap/server/exception/code/TaskErrorCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public enum TaskErrorCode implements BaseErrorCode {
1818
NOT_A_REVIEWER(HttpStatus.FORBIDDEN, "TASK_009", "작업 승인 및 수정 권한이 없습니다."),
1919
NOT_A_REQUESTER(HttpStatus.FORBIDDEN, "TASK_010", "작업 수정 및 취소 권한이 없습니다."),
2020
TASK_STATUS_NOT_ALLOWED(HttpStatus.BAD_REQUEST, "TASK_011", "변경할 수 없는 작업 상태입니다. 다른 API를 사용해주세요"),
21-
FILE_COUNT_EXCEEDED(HttpStatus.BAD_REQUEST, "TASK_012", "파일은 5개 이상 첨부 가능합니다.")
21+
FILE_COUNT_EXCEEDED(HttpStatus.BAD_REQUEST, "TASK_012", "파일은 5개 이상 첨부 가능합니다."),
22+
CATEGORY_DUPLICATE(HttpStatus.BAD_REQUEST, "TASK_013", "카테고리 이름 또는 코드는 중복될 수 없습니다.")
2223
;
2324

2425
private final HttpStatus httpStatus;

0 commit comments

Comments
 (0)