William Brown 5 anos atrás
pai
commit
3b74d088d5

BIN
.DS_Store Ver arquivo


+ 14
- 3
pom.xml Ver arquivo

@@ -14,7 +14,7 @@
14 14
 	<parent>
15 15
 		<groupId>org.springframework.boot</groupId>
16 16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
17
+		<version>1.5.11.RELEASE</version>
18 18
 		<relativePath/> <!-- lookup parent from repository -->
19 19
 	</parent>
20 20
 
@@ -50,7 +50,18 @@
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.hsqldb</groupId>
55
+            <artifactId>hsqldb</artifactId>
56
+            <scope>runtime</scope>
57
+        </dependency>
58
+        <dependency>
59
+            <groupId>org.springframework.boot</groupId>
60
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
61
+            <version>RELEASE</version>
62
+            <scope>compile</scope>
63
+        </dependency>
64
+    </dependencies>
54 65
 
55 66
 	<build>
56 67
 		<plugins>
@@ -62,4 +73,4 @@
62 73
 	</build>
63 74
 
64 75
 
65
-</project>
76
+</project>

+ 20
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Ver arquivo

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

+ 21
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Ver arquivo

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

+ 9
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Ver arquivo

@@ -1,6 +1,15 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+
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
4 13
     private Long id;
5 14
 
6 15
     private String name;

+ 7
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Ver arquivo

@@ -1,7 +1,14 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.Id;
6
+
7
+@Entity
3 8
 public class Muffin {
4 9
 
10
+    @Id
11
+    @GeneratedValue
5 12
     private Long id;
6 13
 
7 14
     private String flavor;

+ 5
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Ver arquivo

@@ -2,6 +2,11 @@ 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.data.rest.core.annotation.RepositoryRestResource;
6
+import org.springframework.stereotype.Repository;
5 7
 
8
+@Repository
9
+@RepositoryRestResource(collectionResourceRel = "bakers", path = "bakers")
6 10
 public interface BakerRepository extends CrudRepository<Baker, Long> {
11
+
7 12
 }

+ 5
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Ver arquivo

@@ -2,6 +2,11 @@ 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.data.rest.core.annotation.RepositoryRestResource;
6
+import org.springframework.stereotype.Repository;
5 7
 
8
+@Repository
9
+@RepositoryRestResource(collectionResourceRel = "bakers", path = "bakers")
6 10
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
11
+
7 12
 }