ng-tracker/src/main/java/ru/ulstu/paper/controller/PaperController.java
2018-11-08 19:36:50 +04:00

59 lines
1.9 KiB
Java

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.PaperStatusDto;
import ru.ulstu.paper.service.PaperService;
import java.io.IOException;
import java.util.List;
import static ru.ulstu.paper.controller.PaperController.URL;
@RestController
@RequestMapping(URL)
public class PaperController {
public static final String URL = Constants.API_1_0 + "papers";
private final PaperService paperService;
public PaperController(PaperService paperService) {
this.paperService = paperService;
}
@GetMapping
public Response<List<PaperDto>> getPapers() {
return new Response<>(paperService.findAllDto());
}
@PostMapping
public Response createPaper(@RequestBody PaperDto paperDto) throws IOException {
return new Response(paperService.create(paperDto));
}
@PutMapping
public Response updatePaper(@RequestBody 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);
}
@GetMapping("/statuses")
public Response<List<PaperStatusDto>> getPaperStatuses() {
return new Response<>(paperService.getPaperStatuses());
}
}