diff --git a/Domain-Module/Todo-Module/Todo-Application/src/main/java/com/pawith/todoapplication/service/TodoCreateUseCase.java b/Domain-Module/Todo-Module/Todo-Application/src/main/java/com/pawith/todoapplication/service/TodoCreateUseCase.java index f75c3002..680867d9 100644 --- a/Domain-Module/Todo-Module/Todo-Application/src/main/java/com/pawith/todoapplication/service/TodoCreateUseCase.java +++ b/Domain-Module/Todo-Module/Todo-Application/src/main/java/com/pawith/todoapplication/service/TodoCreateUseCase.java @@ -31,7 +31,8 @@ public class TodoCreateUseCase { public void createTodo(TodoCreateRequest request) { final User accessUser = userUtils.getAccessUser(); - final Long accessUserRegisterId = registerQueryService.findRegisterByTodoTeamIdAndUserId(request.getTodoTeamId(), accessUser.getId()).getId(); + final Long accessUserRegisterId = + registerQueryService.findRegisterByNullableTodoTeamIdAndUserIdAndCategoryId(request.getTodoTeamId(), accessUser.getId(), request.getCategoryId()).getId(); final Category category = categoryQueryService.findCategoryByCategoryId(request.getCategoryId()); final Todo todo = TodoMapper.mapToTodo(request, category, accessUserRegisterId); todoSaveService.saveTodoEntity(todo); diff --git a/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/repository/RegisterQueryRepository.java b/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/repository/RegisterQueryRepository.java index 40037496..02c8ac0a 100644 --- a/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/repository/RegisterQueryRepository.java +++ b/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/repository/RegisterQueryRepository.java @@ -16,4 +16,6 @@ public interface RegisterQueryRepository { Optional findLatestRegisterByUserIdQuery(Long userId); void deleteByRegisterIdsQuery(List registerIds); List findAllIncompleteTodoCountInfoQuery(Pageable pageable); + + Optional findByUserIdAndCategoryId(Long userId, Long categoryId); } diff --git a/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/service/RegisterQueryService.java b/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/service/RegisterQueryService.java index 57a0381e..6e3eb61f 100644 --- a/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/service/RegisterQueryService.java +++ b/Domain-Module/Todo-Module/Todo-Domain/src/main/java/com/pawith/tododomain/service/RegisterQueryService.java @@ -14,6 +14,7 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -36,6 +37,13 @@ public Register findRegisterByTodoTeamIdAndUserId(Long todoTeamId, Long userId) return findRegister(() -> registerRepository.findByTodoTeamIdAndUserId(todoTeamId, userId)); } + public Register findRegisterByNullableTodoTeamIdAndUserIdAndCategoryId(Long todoTeamId, Long userId, Long categoryId) { + if(Objects.isNull(todoTeamId)){ + return findRegister(() -> registerRepository.findByUserIdAndCategoryId(userId, categoryId)); + } + return findRegister(() -> registerRepository.findByTodoTeamIdAndUserId(todoTeamId, userId)); + } + public Register findPresidentRegisterByTodoTeamId(Long todoTeamId){ return findRegister(() -> registerRepository.findByTodoTeamIdAndAuthority(todoTeamId, Authority.PRESIDENT)); } diff --git a/Domain-Module/Todo-Module/Todo-Infrastructure/src/main/java/com/pawith/todoinfrastructure/repository/RegisterRepositoryImpl.java b/Domain-Module/Todo-Module/Todo-Infrastructure/src/main/java/com/pawith/todoinfrastructure/repository/RegisterRepositoryImpl.java index 553791a6..ea38f197 100644 --- a/Domain-Module/Todo-Module/Todo-Infrastructure/src/main/java/com/pawith/todoinfrastructure/repository/RegisterRepositoryImpl.java +++ b/Domain-Module/Todo-Module/Todo-Infrastructure/src/main/java/com/pawith/todoinfrastructure/repository/RegisterRepositoryImpl.java @@ -88,6 +88,19 @@ public void deleteByRegisterIdsQuery(List registerIds) { .execute(); } + @Override + public Optional findByUserIdAndCategoryId(Long userId, Long categoryId) { + QRegister qRegister = QRegister.register; + QTodoTeam qTodoTeam = qRegister.todoTeam; + QCategory qCategory = QCategory.category; + return Optional.ofNullable(queryFactory.select(qRegister) + .from(qRegister) + .join(qTodoTeam) + .join(qCategory).on(qCategory.todoTeam.eq(qTodoTeam)) + .where(qRegister.userId.eq(userId).and(qCategory.id.eq(categoryId))) + .fetchOne()); + } + @Override @SuppressWarnings("unchecked") public List findAllIncompleteTodoCountInfoQuery(Pageable pageable) { diff --git a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventListener.java b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventListener.java index 0e6eebc6..69d682ce 100644 --- a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventListener.java +++ b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventListener.java @@ -16,12 +16,16 @@ public class ChristmasEventListener { @EventListener public void handleEventCreateNewTodoTeam(ChristmasEvent.ChristmasEventCreateNewTodoTeam event) { - final TodoTeam todoTeam = todoTeamQueryService.findTodoTeamById(event.todoTeamId()); - christmasEventService.publishEvent(todoTeam); + if(christmasEventService.isEventDay()){ + final TodoTeam todoTeam = todoTeamQueryService.findTodoTeamById(event.todoTeamId()); + christmasEventService.publishEvent(todoTeam); + } } @EventListener public void handleEventCreateNewRegister(ChristmasEvent.ChristmasEventCreateNewRegister event) { - christmasEventService.addNewRegisterAtChristmasEventTodo(event.todoTeamId(), event.userId()); + if(christmasEventService.isEventDay()){ + christmasEventService.addNewRegisterAtChristmasEventTodo(event.todoTeamId(), event.userId()); + } } } diff --git a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java index b71a5e06..18169eb4 100644 --- a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java +++ b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java @@ -83,4 +83,8 @@ public void addNewRegisterAtChristmasEventTodo(Long todoTeamId, Long userId){ }); } + public Boolean isEventDay(){ + return EVENT_TODO_SCHEDULED_DATE_LIST.contains(LocalDate.now()); + } + }