Elliott Stansbury 5 anni fa
parent
commit
4d5be77424

BIN
.DS_Store Vedi File


+ 42
- 10
pom.xml Vedi File

@@ -10,15 +10,18 @@
10 10
 
11 11
 	<name>bakery</name>
12 12
 	<description>Demo project for Spring Boot</description>
13
-
14 13
 	<parent>
15 14
 		<groupId>org.springframework.boot</groupId>
16 15
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
16
+		<version>1.5.11.RELEASE</version>
18 17
 		<relativePath/> <!-- lookup parent from repository -->
19 18
 	</parent>
20 19
 
21
-	<properties>
20
+
21
+
22
+
23
+
24
+<properties>
22 25
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23 26
 		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24 27
 		<java.version>1.8</java.version>
@@ -26,13 +29,13 @@
26 29
 
27 30
 	<dependencies>
28 31
 		<dependency>
29
-			<groupId>org.springframework.boot</groupId>
30
-			<artifactId>spring-boot-starter</artifactId>
32
+			<groupId>org.hsqldb</groupId>
33
+			<artifactId>hsqldb</artifactId>
34
+			<scope>runtime</scope>
31 35
 		</dependency>
32
-
33 36
 		<dependency>
34 37
 			<groupId>org.springframework.boot</groupId>
35
-			<artifactId>spring-boot-starter-data-rest</artifactId>
38
+			<artifactId>spring-boot-starter-data-jpa</artifactId>
36 39
 		</dependency>
37 40
 
38 41
 		<dependency>
@@ -41,15 +44,44 @@
41 44
 		</dependency>
42 45
 
43 46
 		<dependency>
44
-			<groupId>org.springframework.boot</groupId>
45
-			<artifactId>spring-boot-starter-test</artifactId>
46
-			<scope>test</scope>
47
+			<groupId>com.h2database</groupId>
48
+			<artifactId>h2</artifactId>
49
+		</dependency>
50
+
51
+		<dependency>
52
+			<groupId>org.hsqldb</groupId>
53
+			<artifactId>hsqldb</artifactId>
54
+			<scope>runtime</scope>
47 55
 		</dependency>
48 56
 		<dependency>
49 57
 			<groupId>org.springframework.data</groupId>
50 58
 			<artifactId>spring-data-commons</artifactId>
51 59
 			<version>1.13.10.RELEASE</version>
52 60
 		</dependency>
61
+		<dependency>
62
+			<groupId>org.springframework.boot</groupId>
63
+			<artifactId>spring-boot-starter-data-jpa</artifactId>
64
+			<version>2.0.4.RELEASE</version>
65
+			<scope>compile</scope>
66
+		</dependency>
67
+		<dependency>
68
+			<groupId>junit</groupId>
69
+			<artifactId>junit</artifactId>
70
+			<version>4.12</version>
71
+			<scope>test</scope>
72
+		</dependency>
73
+		<dependency>
74
+			<groupId>org.springframework</groupId>
75
+			<artifactId>spring-test</artifactId>
76
+			<version>5.1.3.RELEASE</version>
77
+			<scope>test</scope>
78
+		</dependency>
79
+		<dependency>
80
+			<groupId>org.springframework.boot</groupId>
81
+			<artifactId>spring-boot-test</artifactId>
82
+			<version>2.1.1.RELEASE</version>
83
+			<scope>test</scope>
84
+		</dependency>
53 85
 	</dependencies>
54 86
 
55 87
 	<build>

+ 6
- 1
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Vedi File

@@ -2,13 +2,18 @@ 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;
7
-
8
+import org.springframework.web.bind.annotation.GetMapping;
9
+import org.springframework.web.bind.annotation.RestController;
10
+@RestController
8 11
 public class BakerController {
9 12
 
13
+    @Autowired
10 14
     private BakerRepository bakerRepository;
11 15
 
16
+    @GetMapping("/make/{name}")
12 17
     public ResponseEntity<Iterable<Baker>> index() {
13 18
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 19
     }

+ 6
- 0
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Vedi File

@@ -2,13 +2,19 @@ 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("/make/{name}")
12 18
     public ResponseEntity<Iterable<Muffin>> index() {
13 19
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 20
     }

+ 25
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Vedi File

@@ -1,6 +1,17 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import org.springframework.boot.autoconfigure.domain.EntityScan;
4
+
5
+import javax.persistence.Entity;
6
+import javax.persistence.GeneratedValue;
7
+import javax.persistence.GenerationType;
8
+import javax.persistence.Id;
9
+
10
+@Entity
3 11
 public class Baker {
12
+    @Id
13
+    @GeneratedValue(strategy = GenerationType.AUTO)
14
+
4 15
     private Long id;
5 16
 
6 17
     private String name;
@@ -9,6 +20,10 @@ public class Baker {
9 20
 
10 21
     private String specialty;
11 22
 
23
+    public Baker(){
24
+
25
+    }
26
+
12 27
     public Baker(String name, String employeeId, String specialty) {
13 28
         this.name = name;
14 29
         this.employeeId = employeeId;
@@ -46,4 +61,14 @@ public class Baker {
46 61
     public void setSpecialty(String specialty) {
47 62
         this.specialty = specialty;
48 63
     }
64
+
65
+    @Override
66
+    public String toString() {
67
+        return "Baker{" +
68
+                "id=" + id +
69
+                ", name='" + name + '\'' +
70
+                ", employeeId='" + employeeId + '\'' +
71
+                ", specialty='" + specialty + '\'' +
72
+                '}';
73
+    }
49 74
 }

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

@@ -1,6 +1,16 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import org.springframework.boot.autoconfigure.domain.EntityScan;
4
+
5
+import javax.persistence.Entity;
6
+import javax.persistence.GeneratedValue;
7
+import javax.persistence.GenerationType;
8
+import javax.persistence.Id;
9
+
10
+@Entity
3 11
 public class Muffin {
12
+    @Id
13
+    @GeneratedValue(strategy = GenerationType.AUTO)
4 14
 
5 15
     private Long id;
6 16
 

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Vedi 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 Vedi 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
 }

+ 2
- 0
src/test/java/com/zipcodewilmington/bakery/BakeryApplicationTests.java Vedi File

@@ -5,6 +5,8 @@ import org.junit.runner.RunWith;
5 5
 import org.springframework.boot.test.context.SpringBootTest;
6 6
 import org.springframework.test.context.junit4.SpringRunner;
7 7
 
8
+
9
+
8 10
 @RunWith(SpringRunner.class)
9 11
 @SpringBootTest
10 12
 public class BakeryApplicationTests {