Browse Source

Test passed

Lauren Green 6 years ago
parent
commit
262f89e7f4

+ 26
- 0
src/main/java/io/zipcoder/crudapp/Person.java View File

17
     public Person() {
17
     public Person() {
18
 
18
 
19
     }
19
     }
20
+
21
+    public int getId() {
22
+        return id;
23
+    }
24
+
25
+    public void setId(int id) {
26
+        this.id = id;
27
+    }
28
+
29
+    public String getFirstName() {
30
+        return firstName;
31
+    }
32
+
33
+    public void setFirstName(String firstName) {
34
+        this.firstName = firstName;
35
+    }
36
+
37
+    public String getLastName() {
38
+        return lastName;
39
+    }
40
+
41
+    public void setLastName(String lastName) {
42
+        this.lastName = lastName;
43
+    }
20
 }
44
 }
45
+
46
+

+ 11
- 10
src/main/java/io/zipcoder/crudapp/PersonController.java View File

1
 package io.zipcoder.crudapp;
1
 package io.zipcoder.crudapp;
2
 
2
 
3
 import org.springframework.beans.factory.annotation.Autowired;
3
 import org.springframework.beans.factory.annotation.Autowired;
4
+import org.springframework.http.HttpStatus;
4
 import org.springframework.web.bind.annotation.*;
5
 import org.springframework.web.bind.annotation.*;
5
-
6
-import java.util.ArrayList;
6
+import org.springframework.http.ResponseEntity;
7
 import java.util.List;
7
 import java.util.List;
8
 
8
 
9
 @RestController
9
 @RestController
13
     PersonRepository personRepository;
13
     PersonRepository personRepository;
14
 
14
 
15
     @RequestMapping(value = "/people", method = RequestMethod.POST)
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
     @RequestMapping(value = "/people/{id}", method = RequestMethod.GET)
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
     @RequestMapping(value = "/people", method = RequestMethod.GET)
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
     @RequestMapping(value = "/people/{id}", method = RequestMethod.PUT)
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
     @RequestMapping(value = "/people/{id}", method = RequestMethod.DELETE)
36
     @RequestMapping(value = "/people/{id}", method = RequestMethod.DELETE)