Xcuello 6 years ago
parent
commit
55c96f33d6

BIN
.DS_Store View File


+ 7
- 1
pom.xml View File

@@ -50,7 +50,13 @@
50 50
 			<artifactId>spring-data-commons</artifactId>
51 51
 			<version>1.13.10.RELEASE</version>
52 52
 		</dependency>
53
-	</dependencies>
53
+        <dependency>
54
+            <groupId>org.springframework.boot</groupId>
55
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
56
+            <version>RELEASE</version>
57
+            <scope>compile</scope>
58
+        </dependency>
59
+    </dependencies>
54 60
 
55 61
 	<build>
56 62
 		<plugins>

+ 11
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java View File

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

+ 10
- 0
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

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

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

@@ -1,6 +1,14 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2
+import org.springframework.data.annotation.Id;
2 3
 
4
+import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
6
+
7
+@Entity
3 8
 public class Baker {
9
+
10
+    @Id
11
+    @GeneratedValue
4 12
     private Long id;
5 13
 
6 14
     private String name;
@@ -16,34 +24,42 @@ public class Baker {
16 24
     }
17 25
 
18 26
     public Long getId() {
27
+
19 28
         return id;
20 29
     }
21 30
 
22 31
     public void setId(Long id) {
32
+
23 33
         this.id = id;
24 34
     }
25 35
 
26 36
     public String getName() {
37
+
27 38
         return name;
28 39
     }
29 40
 
30 41
     public void setName(String name) {
42
+
31 43
         this.name = name;
32 44
     }
33 45
 
34 46
     public String getEmployeeId() {
47
+
35 48
         return employeeId;
36 49
     }
37 50
 
38 51
     public void setEmployeeId(String employeeId) {
52
+
39 53
         this.employeeId = employeeId;
40 54
     }
41 55
 
42 56
     public String getSpecialty() {
57
+
43 58
         return specialty;
44 59
     }
45 60
 
46 61
     public void setSpecialty(String specialty) {
62
+
47 63
         this.specialty = specialty;
48 64
     }
49 65
 }

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

@@ -1,28 +1,39 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2
+import org.springframework.data.annotation.Id;
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
2 5
 
6
+@Entity
3 7
 public class Muffin {
4 8
 
9
+    @Id
10
+    @GeneratedValue
5 11
     private Long id;
6 12
 
7 13
     private String flavor;
8 14
 
9 15
     public Muffin(String flavor) {
16
+
10 17
         this.flavor = flavor;
11 18
     }
12 19
 
13 20
     public Long getId() {
21
+
14 22
         return id;
15 23
     }
16 24
 
17 25
     public void setId(Long id) {
26
+
18 27
         this.id = id;
19 28
     }
20 29
 
21 30
     public String getFlavor() {
31
+
22 32
         return flavor;
23 33
     }
24 34
 
25 35
     public void setFlavor(String flavor) {
36
+
26 37
         this.flavor = flavor;
27 38
     }
28 39
 }

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

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

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

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