88 lines
3.4 KiB
Java
88 lines
3.4 KiB
Java
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<PaperListDto, PaperDashboardDto, PaperDto> {
|
|
private final PaperService paperService;
|
|
|
|
public PaperController(PaperService paperService) {
|
|
this.paperService = paperService;
|
|
}
|
|
|
|
@GetMapping("list")
|
|
public Response<PageableItems<PaperListDto>> 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<PageableItems<PaperDashboardDto>> 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<PaperDto> get(@PathVariable("paper-id") Integer paperId) {
|
|
return new Response<>(paperService.findById(paperId));
|
|
}
|
|
|
|
@PostMapping
|
|
public Response<PaperDto> create(@RequestBody @Valid PaperDto paperDto) {
|
|
return new Response<>(paperService.create(paperDto));
|
|
}
|
|
|
|
@PutMapping
|
|
public Response<PaperDto> update(@RequestBody @Valid PaperDto paperDto) {
|
|
return new Response<>(paperService.update(paperDto));
|
|
}
|
|
|
|
@DeleteMapping("/{paper-id}")
|
|
public Response<Boolean> 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<List<User>> getAllAuthors() {
|
|
return new Response<>(paperService.getPaperAuthors());
|
|
}
|
|
|
|
@GetMapping("allTypes")
|
|
public Response<List<PaperTypeDto>> getPaperTypes() {
|
|
return new Response<>(paperService.getPaperTypes());
|
|
}
|
|
|
|
@GetMapping("allStatuses")
|
|
public Response<List<PaperStatusDto>> getPaperStatuses() {
|
|
return new Response<>(paperService.getPaperStatuses());
|
|
}
|
|
}
|