fix create paper
parent
67f440ac8a
commit
54bf5735e5
@ -0,0 +1,58 @@
|
||||
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.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<List<PaperDto>> getPapers() {
|
||||
return new Response<>(paperService.findAllDto());
|
||||
}
|
||||
|
||||
@GetMapping("/{paper-id}")
|
||||
public Response<PaperDto> getPaper(@PathVariable("paper-id") Integer paperId){
|
||||
return new Response(paperService.findById(paperId));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue