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 @@ -50,14 +50,22 @@ public List<Category> findSubCategory() {
}

@Override
public boolean existsMainCategoryByNameOrCode(String name, String code) {
return categoryRepository.existsByNameOrCodeAndMainCategoryIsNullAndIsDeletedFalse(name, code);
public boolean existsMainCategoryByNameOrCode(Category category, String name, String code) {
if (category == null) {
return categoryRepository.existsByNameOrCodeAndMainCategoryIsNullAndIsDeletedFalse(name, code);
}
CategoryEntity categoryEntity = categoryPersistenceMapper.toEntity(category);
return categoryRepository.existsByNameOrCodeAndMainCategoryIsNullAndIsDeletedFalse(categoryEntity, name, code);
}

@Override
public boolean existsSubCategoryByNameOrCode(Category category, String name, String code) {
public boolean existsSubCategoryByNameOrCode(Category category, Category mainCategory, String name, String code) {
CategoryEntity mainCategoryEntity = categoryPersistenceMapper.toEntity(mainCategory);
if (category == null) {
return categoryRepository.existsByMainCategoryAndIsDeletedFalseAndNameOrCode(mainCategoryEntity, name, code);
}
CategoryEntity categoryEntity = categoryPersistenceMapper.toEntity(category);
return categoryRepository.existsByMainCategoryAndIsDeletedFalseAndNameOrCode(categoryEntity, name, code);
return categoryRepository.existsByMainCategoryAndIsDeletedFalseAndNameOrCode(categoryEntity, mainCategoryEntity, name, code);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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;
Expand All @@ -11,12 +12,28 @@
public interface CategoryRepository extends JpaRepository<CategoryEntity, Long> {

List<CategoryEntity> findByIsDeletedFalse();

List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNull();

List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNotNull();

@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);
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 IS NULL AND c.isDeleted = false AND c != :category AND (c.name = :name OR c.code = :code)")
boolean existsByNameOrCodeAndMainCategoryIsNullAndIsDeletedFalse(@Param("category") CategoryEntity category,
@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);
boolean existsByMainCategoryAndIsDeletedFalseAndNameOrCode(@Param("mainCategory") CategoryEntity mainCategory,
@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 != :category AND (c.name = :name OR c.code = :code)")
boolean existsByMainCategoryAndIsDeletedFalseAndNameOrCode(@Param("category") CategoryEntity category,
@Param("mainCategory") CategoryEntity mainCategory,
@Param("name") String name,
@Param("code") String code);
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class TaskCustomRepositoryImpl implements TaskCustomRepository {
public Page<TaskEntity> findTasksRequestedByUser(Long requesterId, Pageable pageable, FilterTaskListRequest filterTaskListRequest) {
BooleanBuilder builder = createFilter(filterTaskListRequest);
if (!filterTaskListRequest.nickName().isEmpty()) {
builder.and(taskEntity.processor.nickname.contains(filterTaskListRequest.nickName()));
builder.and(taskEntity.processor.nickname.startsWith(filterTaskListRequest.nickName()));
}
builder.and(taskEntity.requester.memberId.eq(requesterId));

Expand All @@ -51,7 +51,7 @@ public Page<TaskEntity> findTasksRequestedByUser(Long requesterId, Pageable page
public Page<TaskEntity> findTasksAssignedByManager(Long processorId, Pageable pageable, FilterTaskListRequest filterTaskListRequest) {
BooleanBuilder builder = createFilter(filterTaskListRequest);
if (!filterTaskListRequest.nickName().isEmpty()) {
builder.and(taskEntity.requester.nickname.contains(filterTaskListRequest.nickName()));
builder.and(taskEntity.requester.nickname.startsWith(filterTaskListRequest.nickName()));
}
builder.and(taskEntity.processor.memberId.eq(processorId));

Expand Down Expand Up @@ -102,7 +102,7 @@ private BooleanBuilder createFilterBuilder(Long memberId, FilterTeamStatusReques
public Page<TaskEntity> findPendingApprovalTasks(Pageable pageable, FilterTaskListRequest filterTaskListRequest) {
BooleanBuilder builder = createFilter(filterTaskListRequest);
if (!filterTaskListRequest.nickName().isEmpty()) {
builder.and(taskEntity.requester.nickname.contains(filterTaskListRequest.nickName()));
builder.and(taskEntity.requester.nickname.startsWith(filterTaskListRequest.nickName()));
}
builder.and(taskEntity.taskStatus.eq(TaskStatus.REQUESTED));
return getTasksPage(pageable, builder, filterTaskListRequest.sortBy(), filterTaskListRequest.sortDirection());
Expand All @@ -113,8 +113,8 @@ public Page<TaskEntity> findAllTasks(Pageable pageable, FilterTaskListRequest fi
BooleanBuilder builder = createFilter(filterTaskListRequest);
if (!filterTaskListRequest.nickName().isEmpty()) {
builder.and(
taskEntity.requester.nickname.contains(filterTaskListRequest.nickName())
.or(taskEntity.processor.nickname.contains(filterTaskListRequest.nickName()))
taskEntity.requester.nickname.startsWith(filterTaskListRequest.nickName())
.or(taskEntity.processor.nickname.startsWith(filterTaskListRequest.nickName()))
);
}
return getTasksPage(pageable, builder, filterTaskListRequest.sortBy(), filterTaskListRequest.sortDirection());
Expand Down Expand Up @@ -199,11 +199,12 @@ private Page<TaskEntity> getTasksPage(Pageable pageable, BooleanBuilder builder,
.limit(pageable.getPageSize())
.fetch();
long total = queryFactory
.selectFrom(taskEntity)
.leftJoin(taskEntity.processor).fetchJoin()
.leftJoin(taskEntity.requester).fetchJoin()
.select(taskEntity.count())
.from(taskEntity)
.leftJoin(taskEntity.processor)
.leftJoin(taskEntity.requester)
.where(builder)
.fetch().size();
.fetchOne();
return new PageImpl<>(result, pageable, total);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface LoadCategoryPort {
List<Category> findMainCategory();
List<Category> findSubCategory();

boolean existsMainCategoryByNameOrCode(String name, String code);
boolean existsMainCategoryByNameOrCode(Category category, String name, String code);

boolean existsSubCategoryByNameOrCode(Category category, String name, String code);
boolean existsSubCategoryByNameOrCode(Category category, Category mainCategory, 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.existsMainCategoryByNameOrCode(name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
if (loadCategoryPort.existsMainCategoryByNameOrCode(null, name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category mainCategory = Category.createMainCategory(
activeMember.orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND)),
code, name);
Expand All @@ -42,7 +42,7 @@ public void addSubCategory(Long adminId, Long mainCategoryId, String code, Strin
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);
if (loadCategoryPort.existsSubCategoryByNameOrCode(null, mainCategory, name, code)) throw new ApplicationException(CATEGORY_DUPLICATE);
Category subCategory = Category.createSubCategory(activeMember, mainCategory,code, name, descriptionExample);
commandCategoryPort.save(subCategory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public void updateCategory(Long adminId, Long categoryId, String name, String co
Category category = loadCategoryPort.findById(categoryId).orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND));
boolean isDuplicate;
if (category.getMainCategory() == null) {
isDuplicate = loadCategoryPort.existsMainCategoryByNameOrCode(name, code);
isDuplicate = loadCategoryPort.existsMainCategoryByNameOrCode(category, name, code);
} else {
isDuplicate = loadCategoryPort.existsSubCategoryByNameOrCode(category.getMainCategory(), name, code);
isDuplicate = loadCategoryPort.existsSubCategoryByNameOrCode(category, category.getMainCategory(), name, code);
}
if (isDuplicate) throw new ApplicationException(CATEGORY_DUPLICATE);

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ springdoc:
api-docs:
path: /swagger/v3/api-docs

---
---
spring.config.activate.on-profile: "prod"
swagger.server.url: ${SWAGGER_SERVER_URL:http://localhost:8080}
Expand Down