Deleting a task

Only admin users can delete an existing task. The delete option is visible in the task list screen. The controller method of deleting a task looks as follows:

@PostMapping("/deleteTask")
fun deleteTask(@RequestParam(name = "taskId",required = true) taskId:Int,model:Model):String{
var selectedTask:Task? = taskRepository?.findById(taskId)?.get()
if(selectedTask !=null) {
taskRepository?.delete(selectedTask)
}
return "redirect:allTaskList"
}

The taskId parameter is provided in the task list screen. First, we fetch the object of Task with taskId from taskRepository and delete if it is not null. Finally, we redirect to another controller method with the /allTaskList URL to show the task list screen.

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

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