diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 1d0272d..affdaec 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.project.service.ProjectService; @@ -21,7 +20,6 @@ import java.util.List; import java.util.stream.Collectors; import static org.springframework.util.StringUtils.isEmpty; -import static ru.ulstu.core.controller.Navigation.hasErrors; @Controller() @RequestMapping(value = "/projects") diff --git a/src/main/java/ru/ulstu/project/service/ProjectService.java b/src/main/java/ru/ulstu/project/service/ProjectService.java index c15d590..b411c3b 100644 --- a/src/main/java/ru/ulstu/project/service/ProjectService.java +++ b/src/main/java/ru/ulstu/project/service/ProjectService.java @@ -5,6 +5,8 @@ import org.springframework.transaction.annotation.Transactional; import org.thymeleaf.util.StringUtils; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.service.FileService; +import ru.ulstu.grant.model.Grant; +import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -62,6 +64,16 @@ public class ProjectService { return newProject; } + @Transactional + public Project update(ProjectDto projectDto) throws IOException { + Project project = projectRepository.findOne(projectDto.getId()); + if (projectDto.getApplicationFileName() != null && project.getApplication() != null) { + fileService.deleteFile(project.getApplication()); + } + projectRepository.save(copyFromDto(project, projectDto)); + return project; + } + private Project copyFromDto(Project project, ProjectDto projectDto) throws IOException { project.setDescription(projectDto.getDescription()); project.setStatus(projectDto.getStatus() == null ? APPLICATION : projectDto.getStatus()); @@ -85,10 +97,6 @@ public class ProjectService { } } - private Project update(ProjectDto projectDto) { - throw new RuntimeException("not implemented yet"); - } - public Project findById(Integer id) { return projectRepository.findOne(id); } diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index 6bb134e..f821549 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -40,7 +40,7 @@