-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPersonController.java
More file actions
43 lines (31 loc) · 1.24 KB
/
PersonController.java
File metadata and controls
43 lines (31 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package io.zipcoder.crudapp;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class PersonController {
private PersonService service;
public PersonController(PersonService service) {
this.service = service;
}
@GetMapping("/people")
public ResponseEntity<Iterable<Person>> getPersonList() {
return new ResponseEntity<>(service.index(), HttpStatus.OK);
}
@GetMapping("/people/{id}")
public ResponseEntity<Person> getPerson(@PathVariable Long id) {
return new ResponseEntity<>(service.show(id), HttpStatus.OK);
}
@PostMapping("/people")
public ResponseEntity<Person> createPerson (Person person) {
return new ResponseEntity<>(service.create(person), HttpStatus.CREATED);
}
@PutMapping("/people/{id}")
public ResponseEntity<Person> updatePerson(@PathVariable Long id, Person person) {
return new ResponseEntity<>(service.update(id, person), HttpStatus.OK);
}
@DeleteMapping("/people/{id}")
public ResponseEntity<Boolean> deletePerson(@PathVariable Long id) {
return new ResponseEntity<>(service.delete(id), HttpStatus.OK);
}
}