Selaa lähdekoodia

added requestbodies

Jennifer Chao 5 vuotta sitten
vanhempi
commit
4486e8dbaf

+ 2
- 2
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Näytä tiedosto

@@ -29,12 +29,12 @@ public class BakerController {
29 29
     }
30 30
 
31 31
     @PostMapping(path = "/bakers")
32
-    public ResponseEntity<Baker> create(Baker baker) {
32
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
33 33
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
34 34
     }
35 35
 
36 36
     @PutMapping(path = "/bakers/{id}")
37
-    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
37
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
38 38
         Baker foundBaker = bakerRepository.findOne(id);
39 39
 
40 40
         foundBaker.setName(baker.getName());

+ 2
- 2
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Näytä tiedosto

@@ -24,12 +24,12 @@ public class MuffinController {
24 24
     }
25 25
 
26 26
     @PostMapping(path = "/muffins")
27
-    public ResponseEntity<Muffin> create(Muffin muffin) {
27
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
28 28
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
29 29
     }
30 30
 
31 31
     @PutMapping(path = "/muffins/{id}")
32
-    public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
32
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
33 33
         Muffin foundMuffin = muffinRepository.findOne(id);
34 34
         foundMuffin.setFlavor(muffin.getFlavor());
35 35
 

+ 3
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Näytä tiedosto

@@ -1,4 +1,4 @@
1
-package com.zipcodewilmington.bakery.Models;;
1
+package com.zipcodewilmington.bakery.Models;
2 2
 
3 3
 import javax.persistence.Entity;
4 4
 import javax.persistence.GeneratedValue;
@@ -18,6 +18,8 @@ public class Baker {
18 18
 
19 19
     private String specialty;
20 20
 
21
+    public Baker() {}
22
+
21 23
     public Baker(String name, String employeeId, String specialty) {
22 24
         this.name = name;
23 25
         this.employeeId = employeeId;

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Näytä tiedosto

@@ -14,6 +14,8 @@ public class Muffin {
14 14
 
15 15
     private String flavor;
16 16
 
17
+    public Muffin(){}
18
+
17 19
     public Muffin(String flavor) {
18 20
         this.flavor = flavor;
19 21
     }