From e163529d663da67f0a6b420b467fcd94bb7d9f8e Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Thu, 11 Oct 2018 10:03:44 +0400 Subject: [PATCH] load paper statuses --- .../paper/controller/PaperController.java | 16 ++++++++++++++-- .../ru/ulstu/paper/model/PaperStatusDto.java | 19 +++++++++++++++++++ .../ru/ulstu/paper/service/PaperService.java | 5 +++++ src/main/resources/public/js/papers.js | 1 + .../resources/templates/papers/paper.html | 7 ++++++- 5 files changed, 45 insertions(+), 3 deletions(-) create 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 50ff1a4..0672f82 100644 --- a/src/main/java/ru/ulstu/paper/controller/PaperController.java +++ b/src/main/java/ru/ulstu/paper/controller/PaperController.java @@ -1,10 +1,17 @@ package ru.ulstu.paper.controller; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +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.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.PaperStatusDto; import ru.ulstu.paper.service.PaperService; import java.io.IOException; @@ -43,4 +50,9 @@ public class PaperController { paperService.delete(paperId); return new Response(true); } + + @GetMapping("/statuses") + 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..d95b19e --- /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.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 563c86a..5b22cdf 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -5,6 +5,7 @@ import org.springframework.transaction.annotation.Transactional; import ru.ulstu.file.service.FileService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.repository.PaperRepository; import java.io.IOException; @@ -75,4 +76,8 @@ public class PaperService { } paperRepository.delete(paper); } + + public List getPaperStatuses() { + return convert(Arrays.asList(Paper.PaperStatus.values()), status ->new PaperStatusDto(status)); + } } diff --git a/src/main/resources/public/js/papers.js b/src/main/resources/public/js/papers.js index a1a508c..bab27a7 100644 --- a/src/main/resources/public/js/papers.js +++ b/src/main/resources/public/js/papers.js @@ -1,4 +1,5 @@ var urlPapers = "https://localhost:8443/api/1.0/papers"; +var urlPaperStatuses = "https://localhost:8443/api/1.0/papers/statuses"; function showPapers(papersElement) { getFromRest(urlPapers, function (paperList) { diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index e3ae274..66c5405 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -76,6 +76,7 @@ +