63 lines
2.1 KiB
Java
63 lines
2.1 KiB
Java
package ru.ulstu.paper.controller;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.ModelMap;
|
|
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 ru.ulstu.core.model.response.Response;
|
|
import ru.ulstu.paper.model.PaperDto;
|
|
import ru.ulstu.paper.model.PaperFilterDto;
|
|
import ru.ulstu.paper.model.PaperStatusDto;
|
|
import ru.ulstu.paper.service.PaperService;
|
|
|
|
import javax.validation.Valid;
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
|
|
@Controller()
|
|
@RequestMapping(value = "/papers")
|
|
public class PaperController {
|
|
private final PaperService paperService;
|
|
|
|
public PaperController(PaperService paperService) {
|
|
this.paperService = paperService;
|
|
}
|
|
|
|
@GetMapping("/papers")
|
|
public void getPapers(ModelMap modelMap) {
|
|
modelMap.put("papers", paperService.findAllDto());
|
|
}
|
|
|
|
@PostMapping
|
|
public Response<Integer> createPaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
|
|
return new Response<>(paperService.create(paperDto));
|
|
}
|
|
|
|
@PutMapping
|
|
public Response<Integer> updatePaper(@RequestBody @Valid PaperDto paperDto) throws IOException {
|
|
return new Response<>(paperService.update(paperDto));
|
|
}
|
|
|
|
@DeleteMapping("/{paper-id}")
|
|
public Response<Boolean> 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());
|
|
}
|
|
|
|
@PostMapping("/filter")
|
|
public Response<List<PaperDto>> filter(@RequestBody @Valid PaperFilterDto paperFilterDto) throws IOException {
|
|
return new Response<>(paperService.filter(paperFilterDto));
|
|
}
|
|
}
|