| @@ -2,7 +2,9 @@ package com.ffii.tsms.modules.project.service | |||||
| import com.ffii.core.support.JdbcDao | import com.ffii.core.support.JdbcDao | ||||
| import com.ffii.tsms.modules.project.entity.* | import com.ffii.tsms.modules.project.entity.* | ||||
| import com.ffii.tsms.modules.project.web.models.EditTaskTemplateDetails | |||||
| import org.springframework.stereotype.Service | import org.springframework.stereotype.Service | ||||
| import kotlin.jvm.optionals.getOrNull | |||||
| @Service | @Service | ||||
| class TasksService( | class TasksService( | ||||
| @@ -26,6 +28,21 @@ class TasksService( | |||||
| fun deleteTaskTemplate(id: Long) { | fun deleteTaskTemplate(id: Long) { | ||||
| taskTemplateRepository.deleteById(id) | taskTemplateRepository.deleteById(id) | ||||
| } | } | ||||
| fun getTaskTemplateDetails(id: Long): EditTaskTemplateDetails? { | |||||
| val taskTemplate = taskTemplateRepository.findById(id) | |||||
| return taskTemplate.getOrNull()?.let { | |||||
| EditTaskTemplateDetails( | |||||
| id = it.id, | |||||
| code = it.code, | |||||
| name = it.name, | |||||
| taskIds = it.tasks.map { task: Task -> task.id!! } | |||||
| ) | |||||
| } | |||||
| } | |||||
| fun saveTaskTemplate(code: String, name: String, taskIds: List<Long>, id: Long?): TaskTemplate { | fun saveTaskTemplate(code: String, name: String, taskIds: List<Long>, id: Long?): TaskTemplate { | ||||
| val taskTemplate = if (id != null && id > 0) findTaskTemplate(id) else TaskTemplate() | val taskTemplate = if (id != null && id > 0) findTaskTemplate(id) else TaskTemplate() | ||||
| @@ -1,8 +1,10 @@ | |||||
| package com.ffii.tsms.modules.project.web | package com.ffii.tsms.modules.project.web | ||||
| import com.ffii.core.exception.NotFoundException | |||||
| import com.ffii.tsms.modules.project.entity.Task | import com.ffii.tsms.modules.project.entity.Task | ||||
| import com.ffii.tsms.modules.project.entity.TaskTemplate | import com.ffii.tsms.modules.project.entity.TaskTemplate | ||||
| import com.ffii.tsms.modules.project.service.TasksService | import com.ffii.tsms.modules.project.service.TasksService | ||||
| import com.ffii.tsms.modules.project.web.models.EditTaskTemplateDetails | |||||
| import com.ffii.tsms.modules.project.web.models.NewTaskTemplateRequest | import com.ffii.tsms.modules.project.web.models.NewTaskTemplateRequest | ||||
| import jakarta.validation.Valid | import jakarta.validation.Valid | ||||
| import org.springframework.http.HttpStatus | import org.springframework.http.HttpStatus | ||||
| @@ -26,6 +28,11 @@ class TasksController(private val tasksService: TasksService) { | |||||
| return tasksService.findTaskTemplate(id) | return tasksService.findTaskTemplate(id) | ||||
| } | } | ||||
| @GetMapping("/templatesDetails/{id}") | |||||
| fun taskTemplateDetails(@PathVariable id: Long): EditTaskTemplateDetails { | |||||
| return tasksService.getTaskTemplateDetails(id) ?: throw NotFoundException() | |||||
| } | |||||
| @DeleteMapping("/templates/{id}") | @DeleteMapping("/templates/{id}") | ||||
| @ResponseStatus(HttpStatus.NO_CONTENT) | @ResponseStatus(HttpStatus.NO_CONTENT) | ||||
| fun deleteTaskTemplate(@PathVariable id: Long) { | fun deleteTaskTemplate(@PathVariable id: Long) { | ||||
| @@ -0,0 +1,9 @@ | |||||
| package com.ffii.tsms.modules.project.web.models | |||||
| data class EditTaskTemplateDetails ( | |||||
| val id: Long?, | |||||
| val code: String?, | |||||
| val name: String?, | |||||
| val taskIds: List<Long>? | |||||
| ) | |||||