diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController. java b/src/main/java/ru/ulstu/paper/controller/PaperRestController. java deleted file mode 100644 index e69de29..0000000 diff --git a/src/main/java/ru/ulstu/paper/controller/PaperRestController.java b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java new file mode 100644 index 0000000..e6acc10 --- /dev/null +++ b/src/main/java/ru/ulstu/paper/controller/PaperRestController.java @@ -0,0 +1,58 @@ +package ru.ulstu.paper.controller; + +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.PaperDto; +import ru.ulstu.paper.service.PaperService; + +import javax.validation.Valid; +import java.io.IOException; +import java.util.List; + +import static ru.ulstu.paper.controller.PaperRestController.URL; + +@RestController +@RequestMapping(URL) +public class PaperRestController { + public static final String URL = Constants.API_1_0 + "papers"; + + private final PaperService paperService; + + public PaperRestController(PaperService paperService) { + this.paperService = paperService; + } + + @GetMapping + public Response> getPapers() { + return new Response<>(paperService.findAllDto()); + } + + @GetMapping("/{paper-id}") + public Response getPaper(@PathVariable("paper-id") Integer paperId){ + return new Response(paperService.findById(paperId)); + } + + @PostMapping + public Response createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException { + return new Response<>(paperService.create(paperDto)); + } + + @PutMapping + public Response updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException { + return new Response<>(paperService.update(paperDto)); + } + + @DeleteMapping("/{paper-id}") + public Response delete(@PathVariable("paper-id") Integer paperId) throws IOException { + paperService.delete(paperId); + return new Response<>(true); + } +} diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 1161d2d..fc14dbe 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -42,15 +42,6 @@ public class Paper extends BaseEntity implements UserContainer { } } - /*public enum PaperStatus { - ATTENTION, - ON_PREPARATION, - ON_REVIEW, - DRAFT, - COMPLETED, - FAILED; - }*/ - @NotBlank private String title; diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0f5be19..1eb4d2a 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -158,4 +158,8 @@ public class PaperService { update(paperDto); } } + + public PaperDto findById(Integer paperId) { + return new PaperDto(paperRepository.findOne(paperId)); + } } diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index c9ccc3a..269a0cf 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -1,7 +1,7 @@ + layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml"> @@ -26,23 +26,27 @@
-
+
+
- -

Incorrect title

+

Incorrect title

@@ -55,7 +59,8 @@
-

Incorrect title

+

Incorrect title

@@ -161,9 +166,9 @@ type="submit"> Сохранить - +