Skip to content

Commit

Permalink
Review: Handling tasks by ID instead of project ID and task number
Browse files Browse the repository at this point in the history
  • Loading branch information
StaNov committed Jan 14, 2025
1 parent 2db986d commit 9e937bf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TaskNotificationEnhancer(

notifications.forEach { (source, target) ->
target.linkedTask =
convertedTasks.find { it.project.id == source.project?.id && it.number == source.linkedTask?.number }
convertedTasks[source.id]
?.let { taskModelAssembler.toModel(it) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,13 @@ class TaskService(
}
}

fun getTasksWithScope(taskIds: List<Long>): List<TaskWithScopeView> {
fun getTasksWithScope(taskIds: List<Long>): Map<Long, TaskWithScopeView> {
val tasks = taskRepository.findAllById(taskIds)
return getTasksWithScope(tasks)
val taskIdsWithProjectIdAndNumber = tasks.associate { (it.project.id to it.number) to it.id }
val tasksWithScope = getTasksWithScope(tasks)
return tasksWithScope.associateBy {
taskIdsWithProjectIdAndNumber[it.project.id to it.number] ?: throw IllegalStateException("Item not found")
}
}

private fun getTasksWithScope(tasks: Collection<Task>): List<TaskWithScopeView> {
Expand Down

0 comments on commit 9e937bf

Please sign in to comment.