diff --git a/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java b/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java index fbfb598..7f724aa 100644 --- a/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java +++ b/src/main/java/ru/ulstu/deadline/model/DeadlineDto.java @@ -2,15 +2,20 @@ package ru.ulstu.deadline.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import org.springframework.format.annotation.DateTimeFormat; import java.util.Date; public class DeadlineDto { - private final Integer id; + private Integer id; - private final String description; + private String description; - private final Date date; + @DateTimeFormat(pattern = "yyyy-MM-dd") + private Date date; + + public DeadlineDto() { + } @JsonCreator public DeadlineDto(@JsonProperty("id") Integer id, @@ -38,4 +43,16 @@ public class DeadlineDto { public Date getDate() { return date; } + + public void setId(Integer id) { + this.id = id; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setDate(Date date) { + this.date = date; + } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 01f337d..f6438ab 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -7,19 +7,20 @@ 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.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; -import ru.ulstu.core.model.response.Response; +import ru.ulstu.deadline.model.DeadlineDto; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; -import ru.ulstu.paper.model.PaperFilterDto; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; import javax.validation.Valid; import java.io.IOException; import java.util.List; +import java.util.stream.Collectors; + +import static org.springframework.util.StringUtils.isEmpty; @Controller() @@ -45,7 +46,7 @@ public class PaperController { } } - @PostMapping("/paper") + @PostMapping(value = "/paper", params = "save") public String save(@Valid PaperDto paperDto, Errors errors) throws IOException { if (errors.hasErrors()) { return "/papers/paper"; @@ -54,6 +55,13 @@ public class PaperController { return "redirect:/papers/papers"; } + @PostMapping(value = "/paper", params = "addDeadline") + public String addDeadline(@Valid PaperDto paperDto) { + filterEmptyDeadlines(paperDto); + paperDto.getDeadlines().add(new DeadlineDto()); + return "/papers/paper"; + } + @GetMapping("/delete/{paper-id}") public String delete(@PathVariable("paper-id") Integer paperId) throws IOException { paperService.delete(paperId); @@ -70,8 +78,9 @@ public class PaperController { return paperService.getPaperAuthors(); } - @PostMapping("/filter") - public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { - return new Response<>(paperService.filter(paperFilterDto)); + private void filterEmptyDeadlines(PaperDto paperDto) { + paperDto.setDeadlines(paperDto.getDeadlines().stream() + .filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription())) + .collect(Collectors.toList())); } } diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index e6acc10..66efcc7 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.RestController; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.paper.model.PaperFilterDto; import ru.ulstu.paper.service.PaperService; import javax.validation.Valid; @@ -55,4 +56,9 @@ public class PaperRestController { paperService.delete(paperId); return new Response<>(true); } + + @PostMapping("/filter") + public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { + return new Response<>(paperService.filter(paperFilterDto)); + } } diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 52d0a5d..51fd921 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -20,6 +20,7 @@ public class PaperDto { private Paper.PaperStatus status; private Date createDate; private Date updateDate; + @NotEmpty private List deadlines; private String comment; private Boolean locked; @@ -174,4 +175,8 @@ public class PaperDto { public void setAuthors(Set authors) { this.authors = authors; } + + public void setDeadlines(List deadlines) { + this.deadlines = deadlines; + } } diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index d83ded6..04a07c3 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -1,7 +1,7 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/html"> @@ -26,7 +26,7 @@
-
@@ -57,11 +57,33 @@
- - -

Дедлайны: +

+ +
+ +
+
+ +
+
+ + +
+
+

Incorrect title

+
+ +
Incorrect title

-
@@ -178,7 +128,7 @@
-