From 3d4a7b09f320e48682251149530982eaff2485d0 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Tue, 4 Dec 2018 14:48:39 +0400 Subject: [PATCH] show status --- .../paper/controller/PaperController.java | 18 ++++++++---------- src/main/java/ru/ulstu/paper/model/Paper.java | 18 +++++++++++++----- .../ru/ulstu/paper/model/PaperStatusDto.java | 19 ------------------- .../ru/ulstu/paper/service/PaperService.java | 5 ++--- .../papers/fragments/paperLineFragment.html | 5 ++--- .../resources/templates/papers/paper.html | 4 ++-- .../resources/templates/papers/papers.html | 4 ++-- 7 files changed, 29 insertions(+), 44 deletions(-) delete mode 100644 src/main/java/ru/ulstu/paper/model/PaperStatusDto.java diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index 740d0d6..41d8fbc 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -3,19 +3,17 @@ package ru.ulstu.paper.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; -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 org.springframework.web.servlet.mvc.support.RedirectAttributes; import ru.ulstu.core.model.response.Response; +import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; -import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.service.PaperService; import javax.validation.Valid; @@ -55,15 +53,15 @@ public class PaperController { return "redirect:/papers/papers"; } - @DeleteMapping("/{paper-id}") - public Response delete(@PathVariable("paper-id") Integer paperId) throws IOException { + @GetMapping("/delete/{paper-id}") + public String delete(@PathVariable("paper-id") Integer paperId) throws IOException { paperService.delete(paperId); - return new Response<>(true); + return "redirect:/papers/papers"; } - @GetMapping("/statuses") - public Response> getPaperStatuses() { - return new Response<>(paperService.getPaperStatuses()); + @ModelAttribute("allStatuses") + public List getPaperStatuses() { + return paperService.getPaperStatuses(); } @PostMapping("/filter") diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index edc3f3f..1161d2d 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -19,7 +19,6 @@ import javax.persistence.TemporalType; import javax.validation.constraints.NotNull; import java.util.Date; import java.util.HashSet; -import java.util.List; import java.util.Set; @Entity @@ -32,17 +31,26 @@ public class Paper extends BaseEntity implements UserContainer { COMPLETED("Завершена"), FAILED("Провалены сроки"); - private String name; + private String statusName; PaperStatus(String name) { - this.name = name; + this.statusName = name; } - public String getName() { - return name; + public String getStatusName() { + return statusName; } } + /*public enum PaperStatus { + ATTENTION, + ON_PREPARATION, + ON_REVIEW, + DRAFT, + COMPLETED, + FAILED; + }*/ + @NotBlank private String title; diff --git a/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java b/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java deleted file mode 100644 index d95b19e..0000000 --- a/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java +++ /dev/null @@ -1,19 +0,0 @@ -package ru.ulstu.paper.model; - -public class PaperStatusDto { - private final String id; - private final String name; - - public PaperStatusDto(Paper.PaperStatus status) { - this.id = status.name(); - this.name = status.getName(); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } -} diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 99b5d4f..0f5be19 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -6,7 +6,6 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperFilterDto; -import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -111,8 +110,8 @@ public class PaperService { paperRepository.delete(paper); } - public List getPaperStatuses() { - return convert(Arrays.asList(Paper.PaperStatus.values()), PaperStatusDto::new); + public List getPaperStatuses() { + return Arrays.asList(Paper.PaperStatus.values()); } @Transactional diff --git a/src/main/resources/templates/papers/fragments/paperLineFragment.html b/src/main/resources/templates/papers/fragments/paperLineFragment.html index a9e900c..cf1e00a 100644 --- a/src/main/resources/templates/papers/fragments/paperLineFragment.html +++ b/src/main/resources/templates/papers/fragments/paperLineFragment.html @@ -31,10 +31,9 @@ - + - + diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index bf4886d..b9a7eac 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -41,8 +41,8 @@
- +
diff --git a/src/main/resources/templates/papers/papers.html b/src/main/resources/templates/papers/papers.html index 2132364..738f9f5 100644 --- a/src/main/resources/templates/papers/papers.html +++ b/src/main/resources/templates/papers/papers.html @@ -58,7 +58,7 @@