Skip to content

Commit

Permalink
PET-280 refactor : Key(todo) : Value(List<Assign>) 형태의 맵 반환 메소드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
tlarbals824 committed Dec 26, 2023
1 parent bcc0b37 commit 9a3d53b
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.pawith.tododomain.service;

import com.pawith.commonmodule.annotation.DomainService;
import com.pawith.tododomain.consts.TodoDomainCacheValueConsts;
import com.pawith.tododomain.entity.Assign;
import com.pawith.tododomain.entity.Todo;
import com.pawith.tododomain.exception.AssignNotFoundException;
import com.pawith.tododomain.exception.TodoError;
import com.pawith.tododomain.repository.AssignRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@DomainService
@Transactional(readOnly = true)
Expand All @@ -18,10 +24,17 @@ public class AssignQueryService {

private final AssignRepository assignRepository;

@Cacheable(value = TodoDomainCacheValueConsts.ASSIGN_CACHE_WITH_CATEGORY_ID, key = "#categoryId")
public List<Assign> findAllAssignByCategoryIdAndScheduledDate(Long categoryId, LocalDate scheduledDate) {
return assignRepository.findAllByCategoryIdAndScheduledDateQuery(categoryId, scheduledDate);
}

public Map<Todo, List<Assign>> findMapWithTodoKeyAndAssignListValueByCategoryIdAndScheduledDate(Long categoryId, LocalDate scheduledDate) {
return assignRepository.findAllByCategoryIdAndScheduledDateQuery(categoryId, scheduledDate)
.stream()
.collect(Collectors.groupingBy(Assign::getTodo, LinkedHashMap::new, Collectors.toList()));
}

public List<Assign> findAllByUserIdAndTodoTeamIdAndScheduledDate(Long userId, Long todoTeamId) {
final LocalDate now = LocalDate.now();
return assignRepository.findAllByUserIdAndTodoTeamIdAndScheduledDateQuery(userId, todoTeamId, now);
Expand Down

0 comments on commit 9a3d53b

Please sign in to comment.