From f9670ad0a587aa15bb31d34760230b4371671db4 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 4 Dec 2018 11:35:51 +0400 Subject: [PATCH] pass values for paper --- .../paper/controller/PaperController.java | 6 +- .../java/ru/ulstu/paper/model/PaperDto.java | 84 ++++++++++++------- .../resources/templates/papers/paper.html | 12 +-- .../resources/templates/papers/papers.html | 4 +- 4 files changed, 64 insertions(+), 42 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index d82b04a..360d9d9 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,7 +1,9 @@ package ru.ulstu.paper.controller; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.ui.ModelMap; +import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; @@ -10,6 +12,7 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.core.model.response.Response; import ru.ulstu.paper.model.PaperDto; @@ -46,8 +49,9 @@ public class PaperController { } @PostMapping("/paper") - public void createPaper(@ModelAttribute PaperDto paperDto) throws IOException { + public String createPaper(@ModelAttribute PaperDto paperDto) throws IOException { paperService.create(paperDto); + return "redirect:/papers/papers"; } @PutMapping diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index 2dc9244..2ab9284 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -1,8 +1,7 @@ package ru.ulstu.paper.model; -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; +import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.user.model.UserDto; import javax.validation.constraints.NotNull; @@ -15,11 +14,12 @@ import static ru.ulstu.core.util.StreamApiUtils.convert; public class PaperDto { private Integer id; @NotEmpty - private String title; + private String title; private Paper.PaperStatus status; private Date createDate; private Date updateDate; @NotNull + @DateTimeFormat(pattern = "yyyy-MM-dd") private Date deadlineDate; private String comment; private Boolean locked; @@ -32,32 +32,6 @@ public class PaperDto { public PaperDto() { } - @JsonCreator - public PaperDto(@JsonProperty("id") Integer id, - @JsonProperty("title") String title, - @JsonProperty("status") Paper.PaperStatus status, - @JsonProperty("createDate") Date createDate, - @JsonProperty("updateDate") Date updateDate, - @JsonProperty("deadlineDate") Date deadlineDate, - @JsonProperty("comment") String comment, - @JsonProperty("locked") Boolean locked, - @JsonProperty("tmpFileName") String tmpFileName, - @JsonProperty("authors") Set authors) { - this.id = id; - this.title = title; - this.status = status; - this.createDate = createDate; - this.updateDate = updateDate; - this.deadlineDate = deadlineDate; - this.comment = comment; - this.locked = locked; - this.tmpFileName = tmpFileName; - this.fileId = null; - this.fileName = null; - this.fileCreateDate = null; - this.authors = authors; - } - public PaperDto(Paper paper) { this.id = paper.getId(); this.title = paper.getTitle(); @@ -126,6 +100,58 @@ public class PaperDto { return authors; } + public void setId(Integer id) { + this.id = id; + } + + public void setTitle(String title) { + this.title = title; + } + + public void setStatus(Paper.PaperStatus status) { + this.status = status; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public void setUpdateDate(Date updateDate) { + this.updateDate = updateDate; + } + + public void setDeadlineDate(Date deadlineDate) { + this.deadlineDate = deadlineDate; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public void setLocked(Boolean locked) { + this.locked = locked; + } + + public void setTmpFileName(String tmpFileName) { + this.tmpFileName = tmpFileName; + } + + public void setFileId(Integer fileId) { + this.fileId = fileId; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public void setFileCreateDate(Date fileCreateDate) { + this.fileCreateDate = fileCreateDate; + } + + public void setAuthors(Set authors) { + this.authors = authors; + } + public String getAuthorsString() { return authors .stream() diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 59511bf..1e65963 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -27,21 +27,16 @@
-
- + th:field="*{title}"/>

@@ -55,21 +50,18 @@
diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index 738f9f5..2132364 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -58,7 +58,7 @@