Skip to content

Commit

Permalink
Merge pull request #188 from TEAM-SAMSION/release
Browse files Browse the repository at this point in the history
Pet-275 hotfix : 투두 생성 시 TodoTeamId null인 경우 CategoryId로 Register 조회하도록 수정
  • Loading branch information
tlarbals824 authored Dec 22, 2023
2 parents 09ad91d + 4e1f8a5 commit 52a5518
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public interface RegisterQueryRepository {
Optional<Register> findLatestRegisterByUserIdQuery(Long userId);
void deleteByRegisterIdsQuery(List<Long> registerIds);
<T extends IncompleteTodoCountInfoDao> List<T> findAllIncompleteTodoCountInfoQuery(Pageable pageable);

Optional<Register> findByUserIdAndCategoryId(Long userId, Long categoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ public void deleteByRegisterIdsQuery(List<Long> registerIds) {
.execute();
}

@Override
public Optional<Register> 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<IncompleteTodoCountInfoDaoImpl> findAllIncompleteTodoCountInfoQuery(Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ public void addNewRegisterAtChristmasEventTodo(Long todoTeamId, Long userId){
});
}

public Boolean isEventDay(){
return EVENT_TODO_SCHEDULED_DATE_LIST.contains(LocalDate.now());
}

}

0 comments on commit 52a5518

Please sign in to comment.