Showing the edit task page

Only admin users can edit existing tasks. Admin users can see an Edit button for each task record on taskā€”list screen. Upon clicking it, this method will be triggered. It looks as follows.

@GetMapping("/showEditTask")
fun showEditTask(@RequestParam(name = "taskId",required = true) taskId: Int,
model:Model):String {
val task:Task? = taskRepository?.findById(taskId)?.get()
if(task !=null){
val userId: Int = task.getAssignedTo() ?: 0
val user:User? = userRepository?.findById(userId)?.get()
val taskDto = TaskDTO(task.getId(),task.getTitle(),
task.getDetail(),userId,(user?.getFirstname() + " "+user?.getLastname()),task.getStatus(),null)
model.addAttribute("task",taskDto)
}
logger.info("Going to show Edit task page")
setProcessingData(model, TaskMgmntConstant.TITLE_UPDATE_TASK_PAGE)
model.addAttribute("screenTitle","Edit Task")
return "task-edit"
}

The taskId parameter will be sent as a request parameter from the task list screen. First, we fetch the task object from a given taskId with taskRepository and then copy it to the TaskDTO object. You can see we have declared variables with the val keyword, which is used to declare constants. Kotlin recommends using val in case the variable is not changed after assigning the value. The TaskDTO class is a data class defined in Kotlin as follows:

class TaskDTO( var id :Int?, var title : String?,
var detail : String?, var assignedTo : Int?, var assignedPerson:String?,
var status : String?, var comments : Set<Comments>?)

The Edit Task screen looks as follows:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.229.253