From 51164ce11c5d59359d2440c5038c8658f7ca97f5 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 9 May 2019 00:47:28 +0400 Subject: [PATCH] fix enum dtos --- .../paper/controller/PaperController.java | 19 ------------------- .../paper/controller/PaperRestController.java | 7 ++++--- .../ru/ulstu/paper/model/PaperStatusDto.java | 19 +++++++++++++++++++ .../ru/ulstu/paper/model/PaperTypeDto.java | 19 +++++++++++++++++++ .../ru/ulstu/paper/service/PaperService.java | 10 ++++++---- src/main/resources/static/papers/paper.vue | 4 ++-- 6 files changed, 50 insertions(+), 28 deletions(-) create mode 100644 src/main/java/ru/ulstu/paper/model/PaperStatusDto.java create mode 100644 src/main/java/ru/ulstu/paper/model/PaperTypeDto.java diff --git a/src/main/java/ru/ulstu/paper/controller/PaperController.java b/src/main/java/ru/ulstu/paper/controller/PaperController.java index d2dedb7..d857f04 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -3,22 +3,18 @@ package ru.ulstu.paper.controller; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.GetMapping; 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.conference.service.ConferenceService; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; import ru.ulstu.paper.service.LatexService; import ru.ulstu.paper.service.PaperService; -import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; import javax.validation.Valid; @@ -103,21 +99,6 @@ public class PaperController { return "/papers/paper"; } - @ModelAttribute("allStatuses") - public List getPaperStatuses() { - return paperService.getPaperStatuses(); - } - - @ModelAttribute("allTypes") - public List getPaperTypes() { - return paperService.getPaperTypes(); - } - - @ModelAttribute("allAuthors") - public List getAllAuthors() { - return paperService.getPaperAuthors(); - } - @ModelAttribute("allYears") public List getAllYears() { List years = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java index 3df2e93..5e5496a 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -10,9 +10,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.Response; -import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.PaperStatusDto; +import ru.ulstu.paper.model.PaperTypeDto; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.service.PaperService; import ru.ulstu.user.model.User; @@ -86,12 +87,12 @@ public class PaperRestController { } @GetMapping("/allTypes") - public Response> getPaperTypes() { + public Response> getPaperTypes() { return new Response<>(paperService.getPaperTypes()); } @GetMapping("/allStatuses") - public Response> getPaperStatuses() { + public Response> getPaperStatuses() { return new Response<>(paperService.getPaperStatuses()); } } diff --git a/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java b/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java new file mode 100644 index 0000000..76efd5e --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/PaperStatusDto.java @@ -0,0 +1,19 @@ +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.getStatusName(); + } + + public String getId() { + return id; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/ru/ulstu/paper/model/PaperTypeDto.java b/src/main/java/ru/ulstu/paper/model/PaperTypeDto.java new file mode 100644 index 0000000..de2b4d9 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/model/PaperTypeDto.java @@ -0,0 +1,19 @@ +package ru.ulstu.paper.model; + +public class PaperTypeDto { + private final String id; + private final String name; + + public PaperTypeDto(Paper.PaperType type) { + this.id = type.name(); + this.name = type.getTypeName(); + } + + 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 28c978a..6483062 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -10,6 +10,8 @@ import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperListDto; +import ru.ulstu.paper.model.PaperStatusDto; +import ru.ulstu.paper.model.PaperTypeDto; import ru.ulstu.paper.model.ReferenceDto; import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.timeline.service.EventService; @@ -160,12 +162,12 @@ public class PaperService { paperRepository.delete(paper); } - public List getPaperStatuses() { - return Arrays.asList(Paper.PaperStatus.values()); + public List getPaperStatuses() { + return convert(Arrays.asList(Paper.PaperStatus.values()), PaperStatusDto::new); } - public List getPaperTypes() { - return Arrays.asList(Paper.PaperType.values()); + public List getPaperTypes() { + return convert(Arrays.asList(Paper.PaperType.values()), PaperTypeDto::new); } @Transactional diff --git a/src/main/resources/static/papers/paper.vue b/src/main/resources/static/papers/paper.vue index 677619f..7ee63ed 100644 --- a/src/main/resources/static/papers/paper.vue +++ b/src/main/resources/static/papers/paper.vue @@ -35,7 +35,7 @@
@@ -43,7 +43,7 @@