Connor Dunnigan vor 5 Jahren
Ursprung
Commit
21d785d650

+ 15
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Datei anzeigen

@@ -2,25 +2,35 @@ package com.zipcodewilmington.bakery.Controllers;
2 2
 
3 3
 import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5 6
 import org.springframework.http.HttpStatus;
6 7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.stereotype.Controller;
9
+import org.springframework.web.bind.annotation.*;
7 10
 
11
+@Controller
8 12
 public class BakerController {
13
+
14
+    @Autowired
9 15
     private BakerRepository bakerRepository;
10 16
 
17
+    @GetMapping(value = "/baker")
11 18
     public ResponseEntity<Iterable<Baker>> index() {
12 19
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
13 20
     }
14 21
 
15
-    public ResponseEntity<Baker> show(Long id) {
22
+    @GetMapping(value = "/baker/{id}")
23
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
16 24
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
17 25
     }
18 26
 
19
-    public ResponseEntity<Baker> create(Baker baker) {
27
+    @PostMapping(value = "/baker")
28
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
20 29
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
21 30
     }
22 31
 
23
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
32
+    @PutMapping(value = "/baker/{id}")
33
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
24 34
         Baker foundBaker = bakerRepository.findById(id).get();
25 35
 
26 36
         foundBaker.setName(baker.getName());
@@ -29,7 +39,8 @@ public class BakerController {
29 39
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
30 40
     }
31 41
 
32
-    public ResponseEntity<Boolean> destroy(Long id) {
42
+    @DeleteMapping(value = "/baker/{id}")
43
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
33 44
         this.bakerRepository.deleteById(id);
34 45
         return new ResponseEntity<>(true, HttpStatus.OK);
35 46
     }

+ 13
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Datei anzeigen

@@ -2,32 +2,42 @@ package com.zipcodewilmington.bakery.Controllers;
2 2
 
3 3
 import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5 6
 import org.springframework.http.HttpStatus;
6 7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.stereotype.Controller;
9
+import org.springframework.web.bind.annotation.*;
7 10
 
11
+@Controller
8 12
 public class MuffinController {
9 13
 
14
+    @Autowired
10 15
     private MuffinRepository muffinRepository;
11 16
 
17
+    @GetMapping(value = "/muffin")
12 18
     public ResponseEntity<Iterable<Muffin>> index() {
13 19
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 20
     }
15 21
 
16
-    public ResponseEntity<Muffin> show(Long id) {
22
+    @GetMapping(value = "/muffin/{id}")
23
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 24
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
18 25
     }
19 26
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
27
+    @PostMapping(value = "/muffin")
28
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
21 29
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 30
     }
23 31
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
32
+    @PostMapping(value = "/muffin/{id}")
33
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
25 34
         Muffin foundMuffin = muffinRepository.findById(id).get();
26 35
         foundMuffin.setFlavor(muffin.getFlavor());
27 36
 
28 37
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 38
     }
30 39
 
40
+    @DeleteMapping(value = "/muffin/{id}")
31 41
     public ResponseEntity<Boolean> destroy(Long id) {
32 42
         this.muffinRepository.deleteById(id);
33 43
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Datei anzeigen

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

+ 10
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Datei anzeigen

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

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Datei anzeigen

@@ -4,5 +4,6 @@ import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+@Repository
7 8
 public interface BakerRepository extends CrudRepository<Baker, Long> {
8 9
 }

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Datei anzeigen

@@ -4,5 +4,6 @@ import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+@Repository
7 8
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
8 9
 }