[5b447b0] | 1 | package com.wediscussmovies.project.web.controller.rest;
|
---|
| 2 |
|
---|
| 3 | import com.wediscussmovies.project.LoggedUser;
|
---|
| 4 | import com.wediscussmovies.project.ajaxmodels.Grade;
|
---|
| 5 | import com.wediscussmovies.project.service.PersonService;
|
---|
| 6 | import org.springframework.http.ResponseEntity;
|
---|
| 7 | import org.springframework.web.bind.annotation.*;
|
---|
| 8 |
|
---|
| 9 | @RestController
|
---|
| 10 | @RequestMapping("/api/persons")
|
---|
| 11 | public class PersonRestController {
|
---|
| 12 |
|
---|
| 13 | private final PersonService personService;
|
---|
| 14 |
|
---|
| 15 | public PersonRestController(PersonService personService) {
|
---|
| 16 | this.personService = personService;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | @DeleteMapping("/delete/{id}")
|
---|
| 20 | public ResponseEntity deletePerson(@PathVariable Integer id){
|
---|
| 21 |
|
---|
| 22 | try {
|
---|
| 23 | this.personService.deleteById(id);
|
---|
| 24 | return ResponseEntity.ok(true);
|
---|
| 25 | }
|
---|
| 26 | catch (RuntimeException exception){
|
---|
| 27 | return ResponseEntity.ok(false);
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 | @PostMapping("/grade/{personId}")
|
---|
| 31 | public ResponseEntity addGrade(@PathVariable Integer personId, @RequestBody Grade grade){
|
---|
| 32 | try {
|
---|
| 33 | this.personService.addGradePerson(personId, LoggedUser.getLoggedUser(),grade);
|
---|
| 34 | return ResponseEntity.ok(true);
|
---|
| 35 | }
|
---|
| 36 | catch (RuntimeException exception){
|
---|
| 37 | return ResponseEntity.ok(false);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | }
|
---|
| 41 | }
|
---|