Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLAP-382 카테고리 이름, 코드 중복 체크 로직 수정 #492

Merged
merged 16 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
da9b6fe
CLAP-343 fix: 카테고리 고유코드 및 제목 중복 가능한 문제 수정
hyoseong-Choi Feb 9, 2025
c5b632e
CLAP-343 fix: 카테고리 고유코드 및 제목 중복 가능한 문제 수정
hyoseong-Choi Feb 9, 2025
13a5745
Merge branch 'develop' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 10, 2025
e2372a6
CLAP-356 fix: 카테고리 수정시 고유코드 및 제목 중복 가능한 문제 수정
hyoseong-Choi Feb 10, 2025
0f46554
CLAP-356 카테고리 수정시 고유코드 및 제목 중복 가능한 문제 수정
hyoseong-Choi Feb 10, 2025
0dea66b
Merge branch 'develop' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 10, 2025
ce4b7c7
CLAP-356 카테고리 수정시 고유코드 및 제목 중복 가능한 문제 수정
hyoseong-Choi Feb 10, 2025
5edeb9e
Merge pull request #455 from TaskFlow-CLAP/release
joowojr Feb 10, 2025
e4ab582
Merge branch 'develop' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 10, 2025
fd52f10
Merge branch 'release' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 10, 2025
0a4c60f
Merge pull request #473 from TaskFlow-CLAP/release
joowojr Feb 10, 2025
d1a7cce
Merge branch 'develop' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 11, 2025
6ea29ff
Merge branch 'release' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 11, 2025
f5a0808
Merge branch 'release' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 11, 2025
95aa9ba
CLAP-382 fix: 카테고리 이름, 코드 중복 체크 로직 수정
hyoseong-Choi Feb 11, 2025
7dab99b
Merge branch 'release' of https://github.com/TaskFlow-CLAP/TaskFlow-S…
hyoseong-Choi Feb 11, 2025
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 @@ -50,10 +50,17 @@ public List<Category> findSubCategory() {
}

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

@Override
public boolean existsSubCategoryByNameOrCode(Category category, String name, String code) {
CategoryEntity categoryEntity = categoryPersistenceMapper.toEntity(category);
return categoryRepository.existsByMainCategoryAndIsDeletedFalseAndNameOrCode(categoryEntity, 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
@@ -1,6 +1,8 @@
package clap.server.adapter.outbound.persistense.repository.task;
import clap.server.adapter.outbound.persistense.entity.task.CategoryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -12,5 +14,9 @@ public interface CategoryRepository extends JpaRepository<CategoryEntity, Long>
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNull();
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNotNull();

boolean existsByNameOrCodeAndIsDeletedFalse(String name, String code);
@Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM CategoryEntity c WHERE c.mainCategory IS NULL AND c.isDeleted = false AND (c.name = :name OR c.code = :code)")
boolean existsByNameOrCodeAndMainCategoryIsNullAndIsDeletedFalse(@Param("name") String name, @Param("code") String code);

@Query("SELECT CASE WHEN COUNT(c) > 0 THEN true ELSE false END FROM CategoryEntity c WHERE c.mainCategory = :mainCategory AND c.isDeleted = false AND (c.name = :name OR c.code = :code)")
boolean existsByMainCategoryAndIsDeletedFalseAndNameOrCode(@Param("mainCategory")CategoryEntity mainCategory, @Param("name") String name, @Param("code") String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface LoadCategoryPort {
List<Category> findMainCategory();
List<Category> findSubCategory();

boolean existsByNameOrCode(String name, String code);
boolean existsMainCategoryByNameOrCode(String name, String code);

boolean existsSubCategoryByNameOrCode(Category category, String name, String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +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);
if (loadCategoryPort.existsMainCategoryByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category mainCategory = Category.createMainCategory(
activeMember.orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)),
code, name);
Expand All @@ -39,13 +39,11 @@ public void addMainCategory(Long adminId, String code, String name) {
@Override
@Transactional
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)),
code, name, descriptionExample);
Member activeMember = loadMemberPort.findActiveMemberById(adminId).orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND));
Category mainCategory = loadCategoryPort.findById(mainCategoryId).orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND));

if (loadCategoryPort.existsSubCategoryByNameOrCode(mainCategory, name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category subCategory = Category.createSubCategory(activeMember, mainCategory,code, name, descriptionExample);
commandCategoryPort.save(subCategory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ 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 category = loadCategoryPort.findById(categoryId).orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND));
boolean isDuplicate;
if (category.getMainCategory() == null) {
isDuplicate = loadCategoryPort.existsMainCategoryByNameOrCode(name, code);
} else {
isDuplicate = loadCategoryPort.existsSubCategoryByNameOrCode(category.getMainCategory(), name, code);
}
if (isDuplicate) throw new ApplicationException(CATEGORY_DUPLICATE);

category.updateCategory(admin, name, code, descriptionExample);
commandCategoryPort.save(category);
}
Expand Down
Loading