Browse Source

I had to delete everything but it works now

Whitney Martinez 5 years ago
parent
commit
8c7200be74

+ 8
- 1
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>
@@ -73,4 +80,4 @@
73 80
     </build>
74 81
 
75 82
 
76
-</project>
83
+</project>

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

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

+ 15
- 8
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

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

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

@@ -1,14 +1,23 @@
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
+    @Column(name = "baker_name")
6 12
     private String name;
7
-
13
+    @Column(name = "employee_id")
8 14
     private String employeeId;
9
-
15
+    @Column(name = "specialty_id")
10 16
     private String specialty;
11 17
 
18
+    public Baker() {
19
+    }
20
+
12 21
     public Baker(String name, String employeeId, String specialty) {
13 22
         this.name = name;
14 23
         this.employeeId = employeeId;

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

@@ -1,10 +1,20 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+
4
+import javax.persistence.*;
5
+
6
+@Entity
3 7
 public class Muffin {
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column(name = "muffinid")
4 11
     private Long id;
5
-
12
+    @Column(name = "flavor_id")
6 13
     private String flavor;
7 14
 
15
+    public Muffin() {
16
+    }
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 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
 }