-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathPersonController.java
More file actions
48 lines (38 loc) · 1.66 KB
/
PersonController.java
File metadata and controls
48 lines (38 loc) · 1.66 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
44
45
46
47
48
package io.zipcoder.crudapp;
import org.springframework.stereotype.Controller;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.beans.factory.annotation.Autowired;
@Controller
public class PersonController {
private PersonService service;
@Autowired
public PersonController(PersonService service) {
this.service = service;}
@GetMapping("/people")
public ResponseEntity<Iterable<Person>> showAll() {
return new ResponseEntity<>(service.showAll(), HttpStatus.OK);
}
@GetMapping("/people/{id}")
public ResponseEntity<Person> show(@PathVariable Long id) {
return new ResponseEntity<>(service.show(id), HttpStatus.OK);
}
@PostMapping("/people")
public ResponseEntity<Person> create(@RequestBody Person person) {
return new ResponseEntity<>(service.create(person), HttpStatus.CREATED);
}
@PutMapping("/people/{id}")
public ResponseEntity<Person> update(@PathVariable Long id, @RequestBody Person person) {
return new ResponseEntity<>(service.update(id, person), HttpStatus.OK);
}
@DeleteMapping("/people/{id}")
public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
return new ResponseEntity<>(service.delete(id), HttpStatus.OK);
}
}