Xcuello před 5 roky
rodič
revize
e0ac432c00

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

5
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.ResponseEntity;
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
 @RestController
11
 @RestController
13
 public class BakerController {
12
 public class BakerController {
17
 
16
 
18
     @GetMapping("/bakers")
17
     @GetMapping("/bakers")
19
     public ResponseEntity<Iterable<Baker>> index() {
18
     public ResponseEntity<Iterable<Baker>> index() {
19
+
20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
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
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
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
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
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
         Baker foundBaker = bakerRepository.findOne(id);
38
         Baker foundBaker = bakerRepository.findOne(id);
33
 
39
 
34
         foundBaker.setName(baker.getName());
40
         foundBaker.setName(baker.getName());
36
 
42
 
37
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
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
         this.bakerRepository.delete(id);
49
         this.bakerRepository.delete(id);
50
+
42
         return new ResponseEntity<>(true, HttpStatus.OK);
51
         return new ResponseEntity<>(true, HttpStatus.OK);
43
     }
52
     }
44
 }
53
 }

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

5
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.ResponseEntity;
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
 @RestController
10
 @RestController
12
 public class MuffinController {
11
 public class MuffinController {
19
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
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
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
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
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
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
         Muffin foundMuffin = muffinRepository.findOne(id);
33
         Muffin foundMuffin = muffinRepository.findOne(id);
35
         foundMuffin.setFlavor(muffin.getFlavor());
34
         foundMuffin.setFlavor(muffin.getFlavor());
36
 
35
 
37
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
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
         this.muffinRepository.delete(id);
41
         this.muffinRepository.delete(id);
43
         return new ResponseEntity<>(true, HttpStatus.OK);
42
         return new ResponseEntity<>(true, HttpStatus.OK);
44
     }
43
     }

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

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

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

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