From 019fe7c652f7fdfc6ed457a52e2d5ac99d4e72c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D1=81=D0=B8=D0=BD=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD?= Date: Tue, 23 Apr 2019 10:32:23 +0300 Subject: [PATCH] #97 adding deadlines --- .../project/controller/ProjectController.java | 16 +++++++++++++++- .../resources/templates/projects/project.html | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 7033e6d..1d0272d 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -8,6 +8,8 @@ import org.springframework.web.bind.annotation.ModelAttribute; 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; @@ -61,11 +63,23 @@ public class ProjectController { if (projectDto.getDeadlines().isEmpty()) { errors.rejectValue("deadlines", "errorCode", "Не может быть пустым"); } - hasErrors(errors, "/projects/project"); + if (errors.hasErrors()) { + return "/projects/project"; + } projectService.save(projectDto); return String.format("redirect:%s", "/projects/projects"); } + @PostMapping(value = "/project", params = "addDeadline") + public String addDeadline(@Valid ProjectDto projectDto, Errors errors) { + filterEmptyDeadlines(projectDto); + if (errors.hasErrors()) { + return "/projects/project"; + } + projectDto.getDeadlines().add(new Deadline()); + return "/projects/project"; + } + private void filterEmptyDeadlines(ProjectDto projectDto) { projectDto.setDeadlines(projectDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) diff --git a/src/main/resources/templates/projects/project.html b/src/main/resources/templates/projects/project.html index ad4df25..dc3fa6d 100644 --- a/src/main/resources/templates/projects/project.html +++ b/src/main/resources/templates/projects/project.html @@ -73,11 +73,11 @@
-
- +
-
+