Kaynağa Gözat

new changes

Xcuello 5 yıl önce
ebeveyn
işleme
e0ac432c00

+ 20
- 11
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Dosyayı Görüntüle

@@ -5,9 +5,8 @@ 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.GetMapping;
9
-import org.springframework.web.bind.annotation.PathVariable;
10
-import org.springframework.web.bind.annotation.RestController;
8
+import org.springframework.stereotype.Controller;
9
+import org.springframework.web.bind.annotation.*;
11 10
 
12 11
 @RestController
13 12
 public class BakerController {
@@ -17,18 +16,25 @@ public class BakerController {
17 16
 
18 17
     @GetMapping("/bakers")
19 18
     public ResponseEntity<Iterable<Baker>> index() {
19
+
20 20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
21 21
     }
22
-    @GetMapping("/bakers")
23
-    public ResponseEntity<Baker> show(Long id) {
22
+
23
+    @GetMapping("/bakers/{id}")
24
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
25
+
24 26
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
25 27
     }
26
-    @GetMapping("/bakers")
27
-    public ResponseEntity<Baker> create(Baker baker) {
28
+
29
+    @PostMapping("/bakers")
30
+    public ResponseEntity<Baker> create(@PathVariable Baker baker) {
31
+
28 32
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
29 33
     }
30
-    @GetMapping("/bakers")
31
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
34
+
35
+    @PutMapping("/bakers/{id}")
36
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
37
+
32 38
         Baker foundBaker = bakerRepository.findOne(id);
33 39
 
34 40
         foundBaker.setName(baker.getName());
@@ -36,9 +42,12 @@ public class BakerController {
36 42
 
37 43
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
38 44
     }
39
-    @GetMapping("/bakers")
40
-    public ResponseEntity<Boolean> destroy(Long id) {
45
+
46
+    @DeleteMapping("/bakers/{id}")
47
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
48
+
41 49
         this.bakerRepository.delete(id);
50
+
42 51
         return new ResponseEntity<>(true, HttpStatus.OK);
43 52
     }
44 53
 }

+ 9
- 10
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Dosyayı Görüntüle

@@ -5,8 +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.GetMapping;
9
-import org.springframework.web.bind.annotation.RestController;
8
+import org.springframework.web.bind.annotation.*;
10 9
 
11 10
 @RestController
12 11
 public class MuffinController {
@@ -19,26 +18,26 @@ public class MuffinController {
19 18
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
20 19
     }
21 20
 
22
-    @GetMapping("/bakers")
23
-    public ResponseEntity<Muffin> show(Long id) {
21
+    @GetMapping("/muffins{id}")
22
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
24 23
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
25 24
     }
26 25
 
27
-    @GetMapping("/bakers")
28
-    public ResponseEntity<Muffin> create(Muffin muffin) {
26
+    @PostMapping("/muffins")
27
+    public ResponseEntity<Muffin> create(@PathVariable Muffin muffin) {
29 28
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
30 29
     }
31 30
 
32
-    @GetMapping("/bakers")
33
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
31
+    @PutMapping("/muffins{id}")
32
+    public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
34 33
         Muffin foundMuffin = muffinRepository.findOne(id);
35 34
         foundMuffin.setFlavor(muffin.getFlavor());
36 35
 
37 36
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
38 37
     }
39 38
 
40
-    @GetMapping("/bakers")
41
-    public ResponseEntity<Boolean> destroy(Long id) {
39
+    @DeleteMapping("/muffins{id}")
40
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
42 41
         this.muffinRepository.delete(id);
43 42
         return new ResponseEntity<>(true, HttpStatus.OK);
44 43
     }

+ 3
- 5
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Dosyayı Görüntüle

@@ -1,20 +1,18 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2
-import org.springframework.data.annotation.Id;
3 2
 
3
+import org.springframework.data.annotation.Id;
4 4
 import javax.persistence.Entity;
5 5
 import javax.persistence.GeneratedValue;
6
+import javax.persistence.GenerationType;
6 7
 
7 8
 @Entity
8 9
 public class Baker {
9 10
 
10 11
     @Id
11
-    @GeneratedValue
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
12 13
     private Long id;
13
-
14 14
     private String name;
15
-
16 15
     private String employeeId;
17
-
18 16
     private String specialty;
19 17
 
20 18
     public Baker(String name, String employeeId, String specialty) {

+ 3
- 2
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Dosyayı Görüntüle

@@ -1,15 +1,16 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2
+
2 3
 import org.springframework.data.annotation.Id;
3 4
 import javax.persistence.Entity;
4 5
 import javax.persistence.GeneratedValue;
6
+import javax.persistence.GenerationType;
5 7
 
6 8
 @Entity
7 9
 public class Muffin {
8 10
 
9 11
     @Id
10
-    @GeneratedValue
12
+    @GeneratedValue(strategy = GenerationType.AUTO)
11 13
     private Long id;
12
-
13 14
     private String flavor;
14 15
 
15 16
     public Muffin(String flavor) {