Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Получение количества незавершённых задач в проектах
- @GetMapping("/tasks/count")
- public ResponseEntity<Map<Long, Long>> getUnfinishedTasksCount() {
- return ResponseEntity.ok(projectService.getUnfinishedTasksCount());
- }
- public Map<Long, Long> getUnfinishedTasksCount() {
- // попробовать избавиться от Object[], добавить типизацию
- List<UnfinishedTasksCountDto> results = taskRepository.countUnfinishedTasksByProjectIdOptimized();
- return results.stream()
- .collect(Collectors.toMap(UnfinishedTasksCountDto::getProjectId, UnfinishedTasksCountDto::getUnfinishedTasks));
- }
- @Query("SELECT new com.ssau.todoJpa.dto.UnfinishedTasksCountDto(p.id, COALESCE(COUNT(t.id), 0)) " +
- "FROM Project p " +
- "LEFT JOIN p.tasks t " +
- "WHERE t.isCompleted = false OR t IS NULL " +
- "GROUP BY p.id")
- // Создать interface/DTO, посмотреть spring query projection
- List<UnfinishedTasksCountDto> countUnfinishedTasksByProjectIdOptimized();
- @Setter
- @Getter
- @AllArgsConstructor
- public class UnfinishedTasksCountDto {
- private Long projectId;
- private Long unfinishedTasks;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement