diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index affdaec..ae09658 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -5,6 +5,7 @@ import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -78,6 +79,12 @@ public class ProjectController { return "/projects/project"; } + @GetMapping("/delete/{project-id}") + public String delete(@PathVariable("project-id") Integer projectId) throws IOException { + projectService.delete(projectId); + return String.format("redirect:%s", "/projects/projects"); + } + private void filterEmptyDeadlines(ProjectDto projectDto) { projectDto.setDeadlines(projectDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index c34bf42..247624d 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -72,6 +72,15 @@ public class ProjectService { return project; } + @Transactional + public void delete(Integer projectId) throws IOException { + Project project = projectRepository.findOne(projectId); + if (project.getApplication() != null) { + fileService.deleteFile(project.getApplication()); + } + projectRepository.delete(project); + } + private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { project.setDescription(projectDto.getDescription()); project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index f821549..6bb134e 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -40,7 +40,7 @@
- +
diff --git a/src/main/resources/templates/projects/fragments/projectDashboardFragment.html b/src/main/resources/templates/projects/fragments/projectDashboardFragment.html index 4e6f1e6..027dce7 100644 --- a/src/main/resources/templates/projects/fragments/projectDashboardFragment.html +++ b/src/main/resources/templates/projects/fragments/projectDashboardFragment.html @@ -11,7 +11,6 @@
title -

status

diff --git a/src/main/resources/templates/projects/fragments/projectStatusFragment.html b/src/main/resources/templates/projects/fragments/projectStatusFragment.html index e5da374..d8f29cc 100644 --- a/src/main/resources/templates/projects/fragments/projectStatusFragment.html +++ b/src/main/resources/templates/projects/fragments/projectStatusFragment.html @@ -4,7 +4,7 @@ - +