Browse Source

Bakery ready to deploy

Steffon 5 years ago
parent
commit
3da1d44b4c

+ 7
- 0
pom.xml View File

@@ -58,9 +58,16 @@
58 58
             <artifactId>h2</artifactId>
59 59
         </dependency>
60 60
         <dependency>
61
+            <groupId>org.hsqldb</groupId>
62
+            <artifactId>hsqldb</artifactId>
63
+            <scope>runtime</scope>
64
+        </dependency>
65
+        <dependency>
61 66
             <groupId>org.springframework.boot</groupId>
62 67
             <artifactId>spring-boot-starter-data-jpa</artifactId>
63 68
         </dependency>
69
+
70
+
64 71
     </dependencies>
65 72
 
66 73
     <build>

+ 17
- 5
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java View File

@@ -2,25 +2,37 @@ 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.web.bind.annotation.*;
7 9
 
10
+@RestController
8 11
 public class BakerController {
12
+
13
+    public BakerController() {
14
+    }
15
+
16
+    @Autowired
9 17
     private BakerRepository bakerRepository;
10 18
 
19
+    @RequestMapping(value = "/bakers", method = RequestMethod.GET)
11 20
     public ResponseEntity<Iterable<Baker>> index() {
12 21
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
13 22
     }
14 23
 
15
-    public ResponseEntity<Baker> show(Long id) {
24
+    @RequestMapping( value = "/bakers/{id}", method = RequestMethod.GET)
25
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
16 26
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
17 27
     }
18 28
 
19
-    public ResponseEntity<Baker> create(Baker baker) {
29
+    @RequestMapping(value = "/bakers", method = RequestMethod.POST)
30
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
20 31
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
21 32
     }
22 33
 
23
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
34
+    @PutMapping(path = "/bakers/{id}")
35
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
24 36
         Baker foundBaker = bakerRepository.findById(id).get();
25 37
 
26 38
         foundBaker.setName(baker.getName());
@@ -28,8 +40,8 @@ public class BakerController {
28 40
 
29 41
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
30 42
     }
31
-
32
-    public ResponseEntity<Boolean> destroy(Long id) {
43
+    @DeleteMapping(path = "/bakers/{id}")
44
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
33 45
         this.bakerRepository.findById(id).get();
34 46
         return new ResponseEntity<>(true, HttpStatus.OK);
35 47
     }

+ 14
- 5
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

@@ -2,33 +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.web.bind.annotation.*;
7 9
 
8
-public class MuffinController {
9 10
 
11
+@RestController
12
+public class MuffinController {
13
+    @Autowired
10 14
     private MuffinRepository muffinRepository;
11 15
 
16
+    @RequestMapping(value = "/muffins", method = RequestMethod.GET)
12 17
     public ResponseEntity<Iterable<Muffin>> index() {
13 18
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 19
     }
15 20
 
16
-    public ResponseEntity<Muffin> show(Long id) {
21
+    @RequestMapping(value = "/muffins/{id}", method = RequestMethod.GET)
22
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 23
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
18 24
     }
19 25
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
26
+    @RequestMapping(value = "/muffins", method = RequestMethod.POST)
27
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
21 28
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 29
     }
23 30
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
31
+    @RequestMapping(value = "/muffins/{id}", method = RequestMethod.PUT)
32
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
25 33
         Muffin foundMuffin = muffinRepository.findById(id).get();
26 34
         foundMuffin.setFlavor(muffin.getFlavor());
27 35
 
28 36
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 37
     }
30 38
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
39
+    @RequestMapping(value = "/muffins/{id}" ,method = RequestMethod.DELETE)
40
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 41
         this.muffinRepository.deleteById(id);
33 42
         return new ResponseEntity<>(true, HttpStatus.OK);
34 43
     }

+ 12
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java View File

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

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java View File

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

+ 1
- 1
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java View File

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

+ 1
- 1
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java View File

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