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