#76 delete function added

This commit is contained in:
ASH 2019-04-18 21:57:56 +04:00
parent 9da227ab34
commit 59887e5141
4 changed files with 13 additions and 4 deletions

View File

@ -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<Task.TaskStatus> getTaskStatuses() {
return taskService.getTaskStatuses();

View File

@ -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 {

View File

@ -90,7 +90,7 @@ $(document).ready(function () {
' <div class="modal-dialog modal-sm">\n' +
' <div class="modal-content">\n' +
' <div class="modal-header">\n' +
' <h8 class="modal-title" id="myModalLabel">Удалить статью?</h8>\n' +
' <h8 class="modal-title" id="myModalLabel">Удалить задачу?</h8>\n' +
' <button type="button" class="close" data-dismiss="modal" aria-label="Закрыть"><span\n' +
' aria-hidden="true">&times;</span></button>\n' +
' </div>\n' +

View File

@ -7,7 +7,7 @@
<body>
<div class="container" layout:fragment="content">
<form id="tasks-form" method="post" th:action="@{'/tasks/tasks'}">
<form id="tasks-form" method="post" th:action="@{'/students/tasks'}">
<input th:type="hidden" name="taskDeleteId" id="taskDeleteId"/>
<section id="tasks">
<div class="container">