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 @@ -51,7 +51,7 @@ public List<Category> findSubCategory() {

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface CategoryRepository extends JpaRepository<CategoryEntity, Long>
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNull();
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNotNull();

boolean existsByNameOrCode(String name, String code);
boolean existsByNameOrCodeAndIsDeletedFalse(String name, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.transaction.annotation.Transactional;

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 @@ -25,6 +26,7 @@ public class UpdateCategoryService implements UpdateCategoryUsecase {
@Transactional
public void updateCategory(Long adminId, Long categoryId, String name, String code, String descriptionExample) {
Member admin = loadMemberPort.findActiveMemberById(adminId).orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND));
if (loadCategoryPort.existsByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category category = loadCategoryPort.findById(categoryId)
.orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND));
category.updateCategory(admin, name, code, descriptionExample);
Expand Down
Loading