Brandon Defrancis před 5 roky
rodič
revize
a231cde3dd

+ 8
- 11
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Zobrazit soubor

@@ -5,10 +5,7 @@ import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8
-import org.springframework.web.bind.annotation.PathVariable;
9
-import org.springframework.web.bind.annotation.RequestMapping;
10
-import org.springframework.web.bind.annotation.RequestMethod;
11
-import org.springframework.web.bind.annotation.RestController;
8
+import org.springframework.web.bind.annotation.*;
12 9
 
13 10
 @RestController
14 11
 public class BakerController {
@@ -20,30 +17,30 @@ public class BakerController {
20 17
         this.bakerRepository = bakerRepository;
21 18
     }
22 19
 
23
-    @RequestMapping(value="/bakers", method= RequestMethod.GET)
20
+    @GetMapping(value="/bakers")
24 21
     public ResponseEntity<Iterable<Baker>> index() {
25 22
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
26 23
     }
27 24
 
28
-    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.GET)
25
+    @GetMapping(value="/bakers/{id}")
29 26
     public ResponseEntity<Baker> show(@PathVariable Long id) {
30 27
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
31 28
     }
32 29
 
33
-    @RequestMapping(value="/bakers", method= RequestMethod.POST)
34
-    public ResponseEntity<Baker> create(Baker baker) {
30
+    @PostMapping(value="/bakers")
31
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
35 32
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
36 33
     }
37 34
 
38
-    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.PUT)
39
-    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
35
+    @PutMapping(value="/bakers/{id}")
36
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
40 37
         Baker foundBaker = bakerRepository.findOne(id);
41 38
         foundBaker.setName(baker.getName());
42 39
         foundBaker.setSpecialty(baker.getSpecialty());
43 40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
44 41
     }
45 42
 
46
-    @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.DELETE)
43
+    @DeleteMapping(value="/bakers/{id}")
47 44
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
48 45
         this.bakerRepository.delete(id);
49 46
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 6
- 9
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Zobrazit soubor

@@ -5,10 +5,7 @@ import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8
-import org.springframework.web.bind.annotation.PathVariable;
9
-import org.springframework.web.bind.annotation.RequestMapping;
10
-import org.springframework.web.bind.annotation.RequestMethod;
11
-import org.springframework.web.bind.annotation.RestController;
8
+import org.springframework.web.bind.annotation.*;
12 9
 
13 10
 @RestController
14 11
 public class MuffinController {
@@ -20,22 +17,22 @@ public class MuffinController {
20 17
         this.muffinRepository = muffinRepository;
21 18
     }
22 19
 
23
-    @RequestMapping(value="/muffins", method= RequestMethod.GET)
20
+    @GetMapping(value="/muffins")
24 21
     public ResponseEntity<Iterable<Muffin>> index() {
25 22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
26 23
     }
27 24
 
28
-    @RequestMapping(value="/muffins/{MUFFIN_ID}", method=RequestMethod.GET)
25
+    @GetMapping(value="/muffins/{id}")
29 26
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
30 27
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
31 28
     }
32 29
 
33
-    @RequestMapping(value="/muffins", method= RequestMethod.POST)
30
+    @PostMapping(value="/muffins")
34 31
     public ResponseEntity<Muffin> create(Muffin muffin) {
35 32
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
36 33
     }
37 34
 
38
-    @RequestMapping(value="/muffin/{MUFFIN_ID}", method=RequestMethod.PUT)
35
+    @PutMapping(value="/muffin/{id}")
39 36
     public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
40 37
         Muffin foundMuffin = muffinRepository.findOne(id);
41 38
         foundMuffin.setFlavor(muffin.getFlavor());
@@ -43,7 +40,7 @@ public class MuffinController {
43 40
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
44 41
     }
45 42
 
46
-    @RequestMapping(value="/muffins/{MUFFIN_ID}", method=RequestMethod.DELETE)
43
+    @DeleteMapping(value="/muffins/{id}")
47 44
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
48 45
         this.muffinRepository.delete(id);
49 46
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 3
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Zobrazit soubor

@@ -16,7 +16,7 @@ public class Baker {
16 16
     @Column(name = "NAME")
17 17
     private String name;
18 18
 
19
-    @Column(name = "EMPLOYEEID")
19
+    @Column(name = "EMPLOYEE_ID")
20 20
     private String employeeId;
21 21
 
22 22
     @Column(name = "SPECIALTY")
@@ -28,6 +28,8 @@ public class Baker {
28 28
         this.specialty = specialty;
29 29
     }
30 30
 
31
+    public Baker() { }
32
+
31 33
     public Long getId() {
32 34
         return id;
33 35
     }

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Zobrazit soubor

@@ -16,6 +16,8 @@ public class Muffin {
16 16
     @Column(name = "FLAVOR")
17 17
     private String flavor;
18 18
 
19
+    public Muffin() { }
20
+
19 21
     public Muffin(String flavor) {
20 22
         this.flavor = flavor;
21 23
     }