package ru.ulstu.activity.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.RequestParam; import org.springframework.web.bind.annotation.RestController; import ru.ulstu.activity.api.ActivityController; import ru.ulstu.activity.paper.model.PaperDashboardDto; import ru.ulstu.activity.paper.model.PaperDto; import ru.ulstu.activity.paper.model.PaperListDto; import ru.ulstu.activity.paper.model.PaperStatusDto; import ru.ulstu.activity.paper.model.PaperTypeDto; import ru.ulstu.activity.paper.service.PaperService; import ru.ulstu.configuration.Constants; import ru.ulstu.core.model.response.PageableItems; import ru.ulstu.core.model.response.Response; import ru.ulstu.user.model.User; import javax.validation.Valid; import java.util.List; @RestController @RequestMapping(Constants.API_1_0 + "papers") public class PaperController implements ActivityController { private final PaperService paperService; public PaperController(PaperService paperService) { this.paperService = paperService; } @GetMapping("list") public Response> getList(@RequestParam(value = "offset", defaultValue = "0") int offset, @RequestParam(value = "count", defaultValue = "10") int count) { return new Response<>(paperService.findAllDto(offset, count)); } @GetMapping("dashboard") public Response> getDashboard(@RequestParam(value = "offset", defaultValue = "0") int offset, @RequestParam(value = "count", defaultValue = "10") int count) { return new Response<>(paperService.findAllActiveDto(offset, count)); } @GetMapping("{paper-id}") public Response get(@PathVariable("paper-id") Integer paperId) { return new Response<>(paperService.findById(paperId)); } @PostMapping public Response create(@RequestBody @Valid PaperDto paperDto) { return new Response<>(paperService.create(paperDto)); } @PutMapping public Response update(@RequestBody @Valid PaperDto paperDto) { return new Response<>(paperService.update(paperDto)); } @DeleteMapping("/{paper-id}") public Response delete(@PathVariable("paper-id") Integer paperId) { return new Response<>(paperService.delete(paperId)); } @PostMapping("ping/{paper-id}") public void ping(@PathVariable("paper-id") int paperId) { paperService.ping(paperId); } @GetMapping("allAuthors") public Response> getAllAuthors() { return new Response<>(paperService.getPaperAuthors()); } @GetMapping("allTypes") public Response> getPaperTypes() { return new Response<>(paperService.getPaperTypes()); } @GetMapping("allStatuses") public Response> getPaperStatuses() { return new Response<>(paperService.getPaperStatuses()); } }