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.model.PaperFilterDto; 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); } @PostMapping("/filter") public Response> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException { return new Response<>(paperService.filter(paperFilterDto)); } @GetMapping("formatted-list") public Response> getFormattedPaperList() { return new Response<>(paperService.getFormattedPaperList()); } }