Browse Source

test passing

Christian Sheridan 5 years ago
parent
commit
ccc10a0ba5

BIN
.DS_Store View File


+ 7
- 0
pom.xml View File

@@ -25,6 +25,13 @@
25 25
     </properties>
26 26
 
27 27
     <dependencies>
28
+
29
+        <dependency>
30
+            <groupId>org.hsqldb</groupId>
31
+            <artifactId>hsqldb</artifactId>
32
+            <scope>runtime</scope>
33
+        </dependency>
34
+
28 35
         <dependency>
29 36
             <groupId>org.springframework.boot</groupId>
30 37
             <artifactId>spring-boot-starter</artifactId>

+ 15
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java View File

@@ -2,25 +2,36 @@ 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
+@RestController
8 12
 public class BakerController {
13
+
14
+    @Autowired
9 15
     private BakerRepository bakerRepository;
10 16
 
17
+
18
+    @GetMapping(path = "/bakers")
11 19
     public ResponseEntity<Iterable<Baker>> index() {
12 20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
13 21
     }
14 22
 
15
-    public ResponseEntity<Baker> show(Long id) {
23
+    @GetMapping(path = "/bakers/{id}")
24
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
16 25
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
17 26
     }
18 27
 
28
+    @PostMapping(path = "/bakers")
19 29
     public ResponseEntity<Baker> create(Baker baker) {
20 30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
21 31
     }
22 32
 
23
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
33
+    @PutMapping(path = "/bakers/{id}")
34
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
24 35
         Baker foundBaker = bakerRepository.findById(id).get();
25 36
 
26 37
         foundBaker.setName(baker.getName());
@@ -29,7 +40,8 @@ public class BakerController {
29 40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
30 41
     }
31 42
 
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
     }

+ 13
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

@@ -2,33 +2,43 @@ 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
+@RestController
8 12
 public class MuffinController {
9 13
 
14
+    @Autowired
10 15
     private MuffinRepository muffinRepository;
11 16
 
17
+    @GetMapping(path = "/muffins")
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(path = "/muffins/{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
 
27
+    @PostMapping(path = "/muffins")
20 28
     public ResponseEntity<Muffin> create(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
+    @PutMapping(path = "/muffins/{id}")
33
+    public ResponseEntity<Muffin> update(@PathVariable Long id, 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
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
40
+    @DeleteMapping(path = "/muffins/{id}")
41
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 42
         this.muffinRepository.deleteById(id);
33 43
         return new ResponseEntity<>(true, HttpStatus.OK);
34 44
     }

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

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

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

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

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

@@ -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 View File

@@ -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
 }