|
@@ -1,9 +1,9 @@
|
1
|
1
|
package io.zipcoder.crudapp;
|
2
|
2
|
|
3
|
3
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
4
|
+import org.springframework.http.HttpStatus;
|
4
|
5
|
import org.springframework.web.bind.annotation.*;
|
5
|
|
-
|
6
|
|
-import java.util.ArrayList;
|
|
6
|
+import org.springframework.http.ResponseEntity;
|
7
|
7
|
import java.util.List;
|
8
|
8
|
|
9
|
9
|
@RestController
|
|
@@ -13,23 +13,24 @@ public class PersonController {
|
13
|
13
|
PersonRepository personRepository;
|
14
|
14
|
|
15
|
15
|
@RequestMapping(value = "/people", method = RequestMethod.POST)
|
16
|
|
- public Person createPerson(@RequestBody Person p) {
|
17
|
|
- return personRepository.save(p);
|
|
16
|
+ public ResponseEntity<Person> createPerson(@RequestBody Person p) {
|
|
17
|
+ return new ResponseEntity<>(this.personRepository.save(p), HttpStatus.CREATED);
|
18
|
18
|
}
|
19
|
19
|
|
20
|
20
|
@RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
|
21
|
|
- public Person getPerson(@PathVariable int id) {
|
22
|
|
- return personRepository.findOne(id);
|
|
21
|
+ public ResponseEntity<Person> getPerson(@PathVariable int id) {
|
|
22
|
+ return new ResponseEntity<>(this.personRepository.findOne(id), HttpStatus.OK);
|
23
|
23
|
}
|
24
|
24
|
|
25
|
25
|
@RequestMapping(value = "/people", method = RequestMethod.GET)
|
26
|
|
- public List<Person> getPersonList() {
|
27
|
|
- return personRepository.findAll();
|
|
26
|
+ public ResponseEntity<Iterable<Person>> getPersonList() {
|
|
27
|
+ return new ResponseEntity<>(this.personRepository.findAll(), HttpStatus.OK);
|
28
|
28
|
}
|
29
|
29
|
|
30
|
30
|
@RequestMapping(value = "/people/{id}", method = RequestMethod.PUT)
|
31
|
|
- public Person updatePerson(@RequestBody Person p) {
|
32
|
|
- return personRepository.save(p);
|
|
31
|
+ public ResponseEntity<Person> updatePerson(@RequestBody Person p) {
|
|
32
|
+
|
|
33
|
+ return new ResponseEntity<>(this.personRepository.save(p), HttpStatus.OK);
|
33
|
34
|
}
|
34
|
35
|
|
35
|
36
|
@RequestMapping(value = "/people/{id}", method = RequestMethod.DELETE)
|