#11 Seth-Abrams

Открыто
Seth-Abrams хочет смерджить 6 коммит(ов) из Seth-Abrams/CR-MicroLabs-Annotations-Bakery:master в master

Двоичные данные
.DS_Store Просмотреть файл


+ 11
- 2
pom.xml Просмотреть файл

@@ -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,16 @@
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
+        </dependency>
57
+		<dependency>
58
+			<groupId>org.hsqldb</groupId>
59
+			<artifactId>hsqldb</artifactId>
60
+			<scope>runtime</scope>
61
+		</dependency>
62
+    </dependencies>
54 63
 
55 64
 	<build>
56 65
 		<plugins>

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java Просмотреть файл

@@ -3,6 +3,8 @@ package com.zipcodewilmington.bakery;
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
 
6
+import java.util.logging.Logger;
7
+
6 8
 @SpringBootApplication
7 9
 public class BakeryApplication {
8 10
 

+ 14
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Просмотреть файл

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

+ 14
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Просмотреть файл

@@ -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.web.bind.annotation.*;
7 9
 
10
+@RestController
8 11
 public class MuffinController {
9 12
 
13
+    @Autowired
10 14
     private MuffinRepository muffinRepository;
11 15
 
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
 
16
-    public ResponseEntity<Muffin> show(Long id) {
22
+    @GetMapping("/muffins/{id}")
23
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 24
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 25
     }
19 26
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
27
+    @PostMapping("/muffins")
28
+    public ResponseEntity<Muffin> create(@RequestBody 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("/muffins/{id}")
33
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
25 34
         Muffin foundMuffin = muffinRepository.findOne(id);
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("/muffins/{id}")
41
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 42
         this.muffinRepository.delete(id);
33 43
         return new ResponseEntity<>(true, HttpStatus.OK);
34 44
     }

+ 15
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Просмотреть файл

@@ -1,12 +1,23 @@
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
+    @Id
11
+    @GeneratedValue
4 12
     private Long id;
5 13
 
14
+    @Column
6 15
     private String name;
7 16
 
17
+    @Column
8 18
     private String employeeId;
9 19
 
20
+    @Column
10 21
     private String specialty;
11 22
 
12 23
     public Baker(String name, String employeeId, String specialty) {
@@ -15,6 +26,10 @@ public class Baker {
15 26
         this.specialty = specialty;
16 27
     }
17 28
 
29
+    public Baker() {
30
+
31
+    }
32
+
18 33
     public Long getId() {
19 34
         return id;
20 35
     }

+ 14
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Просмотреть файл

@@ -1,15 +1,29 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+
4
+import javax.persistence.Column;
5
+import javax.persistence.Entity;
6
+import javax.persistence.GeneratedValue;
7
+import javax.persistence.Id;
8
+
9
+@Entity
3 10
 public class Muffin {
4 11
 
12
+    @Id
13
+    @GeneratedValue
5 14
     private Long id;
6 15
 
16
+    @Column
7 17
     private String flavor;
8 18
 
9 19
     public Muffin(String flavor) {
10 20
         this.flavor = flavor;
11 21
     }
12 22
 
23
+    public Muffin(){
24
+
25
+    }
26
+
13 27
     public Long getId() {
14 28
         return id;
15 29
     }

+ 3
- 1
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Просмотреть файл

@@ -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
 
6
-public interface BakerRepository extends CrudRepository<Baker, Long> {
7
+
8
+public interface BakerRepository extends CrudRepository<Baker, Long>{
7 9
 }

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Просмотреть файл

@@ -2,6 +2,7 @@ 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
 
6 7
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7 8
 }