Skip to content

Commit

Permalink
fix: get schedule data
Browse files Browse the repository at this point in the history
  • Loading branch information
farneser committed Jun 23, 2024
1 parent 2e4a60f commit 353aaa2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import org.springframework.data.repository.query.Param
interface ProjectRepository : JpaRepository<Project, Long> {
@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<Project>
fun findByUserId(@Param("userId") userId: Long): List<Project>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ import org.springframework.data.jpa.repository.Query
import org.springframework.data.repository.query.Param

interface StatusRepository : JpaRepository<Status, Long> {
fun findByProjectIdOrderByOrderNumber(projectId: Long): List<Status>

@Query(
value = "SELECT * FROM statuses where project_id = :project_id ORDER BY order_number",
nativeQuery = true
)
fun findByProjectIdOrderByOrderNumber(@Param("project_id") projectId: Long): List<Status>

@Query(
value = "SELECT COUNT(*) FROM tasks where project_id = :project_id AND status_id = :status_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class StatusService(private val statusRepository: StatusRepository) {
val log: Logger = LoggerFactory.getLogger(StatusService::class.java)
}

fun getByUserId(userId: Long): List<Status> {
log.debug("Getting statuses by user id: $userId started at ${System.currentTimeMillis()}")
fun getByProjectId(projectId: Long): List<Status> {
log.debug("Getting statuses by project id: $projectId started at ${System.currentTimeMillis()}")

return statusRepository.findByProjectIdOrderByOrderNumber(userId)
return statusRepository.findByProjectIdOrderByOrderNumber(projectId)
}
}

0 comments on commit 353aaa2

Please sign in to comment.