From f376fedc648537c6c564e4b4cda36b66628ff833 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 26 Nov 2018 23:07:14 +0400 Subject: [PATCH] load paper --- .../paper/controller/PaperController.java | 17 ++++++-- src/main/java/ru/ulstu/paper/model/Paper.java | 5 +++ .../java/ru/ulstu/paper/model/PaperDto.java | 29 ++++++++------ .../ru/ulstu/paper/service/PaperService.java | 4 ++ .../db/changelog-20181111_000000-schema.xml | 6 +++ src/main/resources/public/js/papers.js | 3 +- src/main/resources/templates/default.html | 2 - .../resources/templates/papers/dashboard.html | 2 +- .../papers/fragments/paperLineFragment.html | 4 +- .../resources/templates/papers/paper.html | 40 ++++++++++++++----- .../resources/templates/papers/papers.html | 2 +- 11 files changed, 82 insertions(+), 32 deletions(-) diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 25532d3..d82b04a 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -4,11 +4,13 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.DeleteMapping; 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.PutMapping; 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.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; @@ -34,9 +36,18 @@ public class PaperController { modelMap.put("papers", paperService.findAllDto()); } - @PostMapping - public Response createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException { - return new Response<>(paperService.create(paperDto)); + @GetMapping("/paper") + public void getPapers(ModelMap modelMap, @RequestParam(value="id") Integer id) { + if (id != null && id > 0) { + modelMap.put("paper", paperService.findOneDto(id)); + } else { + modelMap.put("paper", new PaperDto()); + } + } + + @PostMapping("/paper") + public void createPaper(@ModelAttribute PaperDto paperDto) throws IOException { + paperService.create(paperDto); } @PutMapping diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index c2a7f31..edc3f3f 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -14,6 +14,8 @@ import javax.persistence.FetchType; import javax.persistence.JoinColumn; import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.Date; import java.util.HashSet; @@ -48,13 +50,16 @@ public class Paper extends BaseEntity implements UserContainer { private PaperStatus status = PaperStatus.DRAFT; @Column(name = "create_date") + @Temporal(TemporalType.TIMESTAMP) private Date createDate = new Date(); @Column(name = "update_date") + @Temporal(TemporalType.TIMESTAMP) private Date updateDate = new Date(); @Column(name = "deadline_date") @NotNull + @Temporal(TemporalType.DATE) private Date deadlineDate; private String comment; diff --git a/src/main/java/ru/ulstu/paper/model/PaperDto.java b/src/main/java/ru/ulstu/paper/model/PaperDto.java index d9a1229..2dc9244 100644 --- a/src/main/java/ru/ulstu/paper/model/PaperDto.java +++ b/src/main/java/ru/ulstu/paper/model/PaperDto.java @@ -13,21 +13,24 @@ import java.util.stream.Collectors; import static ru.ulstu.core.util.StreamApiUtils.convert; public class PaperDto { - private final Integer id; + private Integer id; @NotEmpty - private final String title; - private final Paper.PaperStatus status; - private final Date createDate; - private final Date updateDate; + private String title; + private Paper.PaperStatus status; + private Date createDate; + private Date updateDate; @NotNull - private final Date deadlineDate; - private final String comment; - private final Boolean locked; - private final String tmpFileName; - private final Integer fileId; - private final String fileName; - private final Date fileCreateDate; - private final Set authors; + private Date deadlineDate; + private String comment; + private Boolean locked; + private String tmpFileName; + private Integer fileId; + private String fileName; + private Date fileCreateDate; + private Set authors; + + public PaperDto() { + } @JsonCreator public PaperDto(@JsonProperty("id") Integer id, diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0e1abbc..a9a199e 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -56,6 +56,10 @@ public class PaperService { return convert(findAll(), PaperDto::new); } + public PaperDto findOneDto(Integer id) { + return new PaperDto(paperRepository.findOne(id)); + } + @Transactional public Integer create(PaperDto paperDto) throws IOException { Paper newPaper = copyFromDto(new Paper(), paperDto); diff --git a/src/main/resources/db/changelog-20181111_000000-schema.xml b/src/main/resources/db/changelog-20181111_000000-schema.xml index 1aa0c64..d292cf7 100644 --- a/src/main/resources/db/changelog-20181111_000000-schema.xml +++ b/src/main/resources/db/changelog-20181111_000000-schema.xml @@ -23,4 +23,10 @@ constraintName="fk_event_child_event" referencedTableName="event" referencedColumnNames="id"/> + + + \ No newline at end of file diff --git a/src/main/resources/public/js/papers.js b/src/main/resources/public/js/papers.js index e8cc7ed..8fbce6f 100644 --- a/src/main/resources/public/js/papers.js +++ b/src/main/resources/public/js/papers.js @@ -32,7 +32,8 @@ function showPapers(papersElement, paperRowClass) { }); } -function deletePaper(id, papersElement, paperRowClass) { +function deletePaper(idElement, papersElement, paperRowClass) { + var id = $(idElement).parent().find('.id-class').val(); $("#remove-paper-modal").modal('show'); $("#modal-btn-yes").on("click", function () { diff --git a/src/main/resources/templates/default.html b/src/main/resources/templates/default.html index b261b2f..a571cb7 100644 --- a/src/main/resources/templates/default.html +++ b/src/main/resources/templates/default.html @@ -88,8 +88,6 @@ - -