From 59887e5141b343d578f9f391d9fb457c8180aa77 Mon Sep 17 00:00:00 2001 From: ASH Date: Thu, 18 Apr 2019 21:57:56 +0400 Subject: [PATCH] #76 delete function added --- .../java/ru/ulstu/students/controller/TaskController.java | 7 +++++++ src/main/java/ru/ulstu/students/service/TaskService.java | 6 ++++-- src/main/resources/public/js/tasks.js | 2 +- src/main/resources/templates/students/tasks.html | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/students/controller/TaskController.java b/src/main/java/ru/ulstu/students/controller/TaskController.java index 8fd9575..ef602e2 100644 --- a/src/main/java/ru/ulstu/students/controller/TaskController.java +++ b/src/main/java/ru/ulstu/students/controller/TaskController.java @@ -71,6 +71,13 @@ public class TaskController { return TASK_PAGE; } + @GetMapping("/delete/{task-id}") + public String delete(@PathVariable("task-id") Integer taskId) throws IOException { + taskService.delete(taskId); + return String.format(REDIRECT_TO, TASKS_PAGE); + } + + @ModelAttribute("allStatuses") public List getTaskStatuses() { return taskService.getTaskStatuses(); diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 7b67a44..d400fa6 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -76,8 +76,10 @@ public class TaskService { @Transactional public void delete(Integer taskId) throws IOException { - Task task = taskRepository.findOne(taskId); - taskRepository.delete(task); + if (taskRepository.exists(taskId)) { + taskRepository.delete(taskId); + } + } public void save(TaskDto taskDto) throws IOException { diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index b333c31..f756199 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -90,7 +90,7 @@ $(document).ready(function () { '