From 353aaa2605ad37bacb2adf98e49bd70885b168ca Mon Sep 17 00:00:00 2001 From: farneser Date: Sun, 23 Jun 2024 06:58:36 +0300 Subject: [PATCH] fix: get schedule data --- .../scheduler/repository/ProjectRepository.kt | 10 +++++----- .../scheduler/repository/StatusRepository.kt | 6 +++++- .../tasktracker/scheduler/services/SchedulerService.kt | 8 ++++++-- .../tasktracker/scheduler/services/StatusService.kt | 6 +++--- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/ProjectRepository.kt b/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/ProjectRepository.kt index 8e1aa9e..b1cbbbb 100644 --- a/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/ProjectRepository.kt +++ b/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/ProjectRepository.kt @@ -8,11 +8,11 @@ import org.springframework.data.repository.query.Param interface ProjectRepository : JpaRepository { @Query( value = """ - SELECT projects.id, projects.project_name - FROM projects - JOIN project_members ON projects.id = project_members.project_id - WHERE project_members.member_id = :user_id; + SELECT p.* + FROM projects p + JOIN project_members pm ON p.id = pm.project_id + WHERE pm.member_id = :userId """, nativeQuery = true ) - fun findByUserId(@Param("user_id") userId: Long): List + fun findByUserId(@Param("userId") userId: Long): List } \ No newline at end of file diff --git a/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/StatusRepository.kt b/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/StatusRepository.kt index 99a42f4..e4814c1 100644 --- a/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/StatusRepository.kt +++ b/src/main/kotlin/dev/farneser/tasktracker/scheduler/repository/StatusRepository.kt @@ -6,8 +6,12 @@ import org.springframework.data.jpa.repository.Query import org.springframework.data.repository.query.Param interface StatusRepository : JpaRepository { - fun findByProjectIdOrderByOrderNumber(projectId: Long): List + @Query( + value = "SELECT * FROM statuses where project_id = :project_id ORDER BY order_number", + nativeQuery = true + ) + fun findByProjectIdOrderByOrderNumber(@Param("project_id") projectId: Long): List @Query( value = "SELECT COUNT(*) FROM tasks where project_id = :project_id AND status_id = :status_id", diff --git a/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt b/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt index c1ed3be..41855be 100644 --- a/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt +++ b/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/SchedulerService.kt @@ -43,14 +43,18 @@ class SchedulerService( val projects = projectService.getByUserId(user.id) + log.info("Projects for user ${user.email}: $projects") + for (project in projects) { val projectDto = ProjectDto(project.projectName ?: "Project name", ArrayList()) - val statuses = statusService.getByUserId(user.id) + val statuses = statusService.getByProjectId(project.id) + + log.info("Statuses in project ${project.projectName}: $statuses") for (status in statuses.filter { it.isCompleted == false }) { - val tasks = taskService.getByProjectId(status.id, user.id) + val tasks = taskService.getByProjectId(project.id, status.id) projectDto.statuses.add(StatusDto(status, tasks)) diff --git a/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/StatusService.kt b/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/StatusService.kt index c701885..f87d7d3 100644 --- a/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/StatusService.kt +++ b/src/main/kotlin/dev/farneser/tasktracker/scheduler/services/StatusService.kt @@ -12,9 +12,9 @@ class StatusService(private val statusRepository: StatusRepository) { val log: Logger = LoggerFactory.getLogger(StatusService::class.java) } - fun getByUserId(userId: Long): List { - log.debug("Getting statuses by user id: $userId started at ${System.currentTimeMillis()}") + fun getByProjectId(projectId: Long): List { + log.debug("Getting statuses by project id: $projectId started at ${System.currentTimeMillis()}") - return statusRepository.findByProjectIdOrderByOrderNumber(userId) + return statusRepository.findByProjectIdOrderByOrderNumber(projectId) } } \ No newline at end of file