瀏覽代碼

updated with the latest code

Demetrius Murray 5 年之前
父節點
當前提交
be28fd6220

二進制
.DS_Store 查看文件


+ 28
- 88
pom.xml 查看文件

@@ -1,124 +1,65 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2
-<<<<<<< HEAD
3
-<project xmlns="http://maven.apache.org/POM/4.0.0"
4
-		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
-		 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6
-	<modelVersion>4.0.0</modelVersion>
7
-
8
-	<groupId>io.zipcoder</groupId>
9
-	<artifactId>spring-demo</artifactId>
10
-	<version>1.0-SNAPSHOT</version>
11
-	<build>
12
-		<plugins>
13
-			<plugin>
14
-				<groupId>org.apache.maven.plugins</groupId>
15
-				<artifactId>maven-compiler-plugin</artifactId>
16
-				<configuration>
17
-					<source>8</source>
18
-					<target>8</target>
19
-				</configuration>
20
-			</plugin>
21
-		</plugins>
22
-	</build>
23
-	<parent>
24
-		<groupId>org.springframework.boot</groupId>
25
-		<artifactId>spring-boot-starter-parent</artifactId>
26
-		<version>1.5.3.RELEASE</version>
27
-		<relativePath/> <!-- lookup parent from repository -->
28
-	</parent>
29
-	<properties>
30
-		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
31
-		<start-class>com.zipcodewilmington.bakery.BakeryApplication</start-class>
32
-		<java.version>1.7</java.version>
33
-	</properties>
34
-	<dependencies>
35
-		<dependency>
36
-			<groupId>org.springframework.boot</groupId>
37
-			<artifactId>spring-boot-starter-web</artifactId>
38
-		</dependency>
39
-		<dependency>
40
-			<groupId>org.springframework.boot</groupId>
41
-			<artifactId>spring-boot-starter-data-jpa</artifactId>
42
-		</dependency>
43
-		<dependency>
44
-			<groupId>org.springframework.boot</groupId>
45
-			<artifactId>spring-boot-starter-test</artifactId>
46
-			<scope>test</scope>
47
-		</dependency>
48
-		<dependency>
49
-			<groupId>org.hsqldb</groupId>
50
-			<artifactId>hsqldb</artifactId>
51
-			<scope>runtime</scope>
52
-		</dependency>
53
-
54
-		<dependency>
55
-			<groupId>javax.inject</groupId>
56
-			<artifactId>javax.inject</artifactId>
57
-			<version>1</version>
58
-		</dependency>
59
-	</dependencies>
60
-=======
61 2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
62 3
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
63 4
     <modelVersion>4.0.0</modelVersion>
64
-
5
+    <parent>
6
+        <groupId>org.springframework.boot</groupId>
7
+        <artifactId>spring-boot-starter-parent</artifactId>
8
+        <version>2.1.1.RELEASE</version>
9
+        <relativePath/> <!-- lookup parent from repository -->
10
+    </parent>
65 11
     <groupId>com.zipcodewilmington</groupId>
66 12
     <artifactId>bakery</artifactId>
67 13
     <version>0.0.1-SNAPSHOT</version>
68 14
     <packaging>jar</packaging>
69
-
70 15
     <name>bakery</name>
71 16
     <description>Demo project for Spring Boot</description>
72 17
 
73
-    <parent>
74
-        <groupId>org.springframework.boot</groupId>
75
-        <artifactId>spring-boot-starter-parent</artifactId>
76
-        <version>2.0.4.RELEASE</version>
77
-        <relativePath/> <!-- lookup parent from repository -->
78
-    </parent>
79
-
80 18
     <properties>
81
-        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
82
-        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
83 19
         <java.version>1.8</java.version>
84 20
     </properties>
85 21
 
86 22
     <dependencies>
23
+        <!-- https://mvnrepository.com/artifact/org.mockito/mockito-all -->
87 24
         <dependency>
88
-            <groupId>org.springframework.boot</groupId>
89
-            <artifactId>spring-boot-starter</artifactId>
25
+            <groupId>javax.xml.bind</groupId>
26
+            <artifactId>jaxb-api</artifactId>
27
+            <version>2.3.0</version>
90 28
         </dependency>
91
-
92 29
         <dependency>
93 30
             <groupId>org.springframework.boot</groupId>
94
-            <artifactId>spring-boot-starter-data-rest</artifactId>
31
+            <artifactId>spring-boot-starter-web</artifactId>
95 32
         </dependency>
96
-
97 33
         <dependency>
98 34
             <groupId>org.springframework.boot</groupId>
99
-            <artifactId>spring-boot-starter-web</artifactId>
35
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
100 36
         </dependency>
101
-
102 37
         <dependency>
103 38
             <groupId>org.springframework.boot</groupId>
104 39
             <artifactId>spring-boot-starter-test</artifactId>
105 40
             <scope>test</scope>
106 41
         </dependency>
107 42
         <dependency>
108
-            <groupId>org.springframework.data</groupId>
109
-            <artifactId>spring-data-commons</artifactId>
43
+            <groupId>org.hsqldb</groupId>
44
+            <artifactId>hsqldb</artifactId>
45
+            <scope>runtime</scope>
110 46
         </dependency>
111 47
         <dependency>
112
-            <groupId>org.springframework.boot</groupId>
113
-            <artifactId>spring-boot-starter-data-jpa</artifactId>
114
-        </dependency>
115
-        <dependency>
116
-            <groupId>com.h2database</groupId>
117
-            <artifactId>h2</artifactId>
48
+            <groupId>javax.inject</groupId>
49
+            <artifactId>javax.inject</artifactId>
50
+            <version>1</version>
118 51
         </dependency>
119 52
         <dependency>
120
-            <groupId>org.springframework.boot</groupId>
121
-            <artifactId>spring-boot-starter-data-jpa</artifactId>
53
+            <groupId>org.mockito</groupId>
54
+            <artifactId>mockito-core</artifactId>
55
+            <version>1.10.19</version>
56
+            <exclusions>
57
+                <exclusion>
58
+                    <groupId>org.hamcrest</groupId>
59
+                    <artifactId>hamcrest-core</artifactId>
60
+                </exclusion>
61
+            </exclusions>
62
+            <scope>test</scope>
122 63
         </dependency>
123 64
     </dependencies>
124 65
 
@@ -130,7 +71,6 @@
130 71
             </plugin>
131 72
         </plugins>
132 73
     </build>
133
->>>>>>> 1356254de500f16124e3fe66a4b3ab488374a38d
134 74
 
135 75
 
136 76
 </project>

二進制
src/main/java/com/zipcodewilmington/bakery/.DS_Store 查看文件


+ 3
- 3
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java 查看文件

@@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
6 6
 @SpringBootApplication
7 7
 public class BakeryApplication {
8 8
 
9
-	public static void main(String[] args) {
10
-		SpringApplication.run(BakeryApplication.class, args);
11
-	}
9
+    public static void main(String[] args) {
10
+        SpringApplication.run(BakeryApplication.class, args);
11
+    }
12 12
 }

+ 28
- 15
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java 查看文件

@@ -2,35 +2,48 @@ 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 com.zipcodewilmington.bakery.Services.BakerService;
6
+import org.springframework.beans.factory.annotation.Autowired;
7
+import org.springframework.context.annotation.Bean;
5 8
 import org.springframework.http.HttpStatus;
6 9
 import org.springframework.http.ResponseEntity;
10
+import org.springframework.stereotype.Controller;
11
+import org.springframework.web.bind.annotation.PathVariable;
12
+import org.springframework.web.bind.annotation.RequestMapping;
13
+import org.springframework.web.bind.annotation.RequestMethod;
14
+import org.springframework.web.bind.annotation.RestController;
7 15
 
16
+@RestController("baker")
8 17
 public class BakerController {
9
-    private BakerRepository bakerRepository;
10 18
 
19
+    @Autowired
20
+    private BakerService bakerService;
21
+
22
+    public BakerController(){
23
+    }
24
+
25
+    @RequestMapping(value = "/bakers", method = RequestMethod.GET)
11 26
     public ResponseEntity<Iterable<Baker>> index() {
12
-        return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
27
+        return new ResponseEntity<>(this.bakerService.find(), HttpStatus.OK);
13 28
     }
14 29
 
15
-    public ResponseEntity<Baker> show(Long id) {
16
-        return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
30
+    @RequestMapping(value = "/bakers/{id}", method = RequestMethod.GET)
31
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
32
+        return new ResponseEntity<>(this.bakerService.findById(id), HttpStatus.OK);
17 33
     }
18 34
 
35
+    @RequestMapping(value = "/bakers", method = RequestMethod.POST)
19 36
     public ResponseEntity<Baker> create(Baker baker) {
20
-        return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
37
+        return new ResponseEntity<>(this.bakerService.create(baker), HttpStatus.CREATED);
21 38
     }
22 39
 
23
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
24
-        Baker foundBaker = bakerRepository.findById(id).get();
25
-
26
-        foundBaker.setName(baker.getName());
27
-        foundBaker.setSpecialty(baker.getSpecialty());
28
-
29
-        return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
40
+    @RequestMapping(value = "/bakers/{id}", method = RequestMethod.PUT)
41
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
42
+        return new ResponseEntity<>(this.bakerService.update(id,baker), HttpStatus.OK);
30 43
     }
31 44
 
32
-    public ResponseEntity<Boolean> destroy(Long id) {
33
-        this.bakerRepository.findById(id).get();
34
-        return new ResponseEntity<>(true, HttpStatus.OK);
45
+    @RequestMapping(value = "/bakers/{id}", method = RequestMethod.DELETE)
46
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
47
+        return new ResponseEntity<>(this.bakerService.destroy(id), HttpStatus.OK);
35 48
     }
36 49
 }

+ 28
- 12
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java 查看文件

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

+ 59
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java 查看文件

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

+ 10
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java 查看文件

@@ -1,10 +1,20 @@
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 {
9
+
10
+    @Id
11
+    @GeneratedValue
4 12
     private Long id;
5 13
 
6 14
     private String flavor;
7 15
 
16
+    public Muffin(){}
17
+
8 18
     public Muffin(String flavor) {
9 19
         this.flavor = flavor;
10 20
     }

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java 查看文件

@@ -4,5 +4,8 @@ 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> {
9
+//    Baker findOne(Long id);
10
+    void deleteById(Long id);
8 11
 }

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java 查看文件

@@ -4,5 +4,8 @@ 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> {
9
+//    Muffin findOne(Long id);
10
+    void deleteById(Long id);
8 11
 }

+ 40
- 0
src/main/java/com/zipcodewilmington/bakery/Services/BakerService.java 查看文件

@@ -0,0 +1,40 @@
1
+package com.zipcodewilmington.bakery.Services;
2
+
3
+import com.zipcodewilmington.bakery.Models.Baker;
4
+import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Service;
7
+
8
+@Service
9
+public class BakerService {
10
+    @Autowired
11
+    private BakerRepository bakerRepository;
12
+
13
+    public BakerService(){}
14
+
15
+    public Iterable<Baker> find() {
16
+        return this.bakerRepository.findAll();
17
+    }
18
+
19
+    public Baker findById(Long id) {
20
+        return this.bakerRepository.findById(id).orElse(null);
21
+    }
22
+
23
+    public Baker create(Baker baker) {
24
+        return this.bakerRepository.save(baker);
25
+    }
26
+
27
+    public Baker update(Long id, Baker baker) {
28
+        Baker foundBaker = bakerRepository.findById(id).orElse(null);
29
+
30
+        foundBaker.setName(baker.getName());
31
+        foundBaker.setSpecialty(baker.getSpecialty());
32
+
33
+        return this.bakerRepository.save(foundBaker);
34
+    }
35
+
36
+    public Boolean destroy(Long id) {
37
+        this.bakerRepository.deleteById(id);
38
+        return true;
39
+    }
40
+}

+ 42
- 0
src/main/java/com/zipcodewilmington/bakery/Services/MuffinService.java 查看文件

@@ -0,0 +1,42 @@
1
+package com.zipcodewilmington.bakery.Services;
2
+
3
+import com.zipcodewilmington.bakery.Models.Muffin;
4
+import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.stereotype.Service;
7
+
8
+@Service
9
+public class MuffinService {
10
+
11
+    private MuffinRepository muffinRepository;
12
+
13
+    @Autowired
14
+    public MuffinService(MuffinRepository muffinRepository) {
15
+        this.muffinRepository = muffinRepository;
16
+    }
17
+
18
+    public Iterable<Muffin> find() {
19
+        return this.muffinRepository.findAll();
20
+    }
21
+
22
+    public Muffin findById(Long id) {
23
+        return this.muffinRepository.findById(id).orElse(null);
24
+    }
25
+
26
+    public Muffin create(Muffin muffin) {
27
+        return this.muffinRepository.save(muffin);
28
+    }
29
+
30
+    public Muffin update(Long id, Muffin muffin) {
31
+        Muffin foundMuffin = muffinRepository.findById(id).orElse(null);
32
+        assert foundMuffin != null;
33
+        foundMuffin.setFlavor(muffin.getFlavor());
34
+
35
+        return this.muffinRepository.save(muffin);
36
+    }
37
+
38
+    public Boolean destroy(Long id) {
39
+        this.muffinRepository.deleteById(id);
40
+        return true;
41
+    }
42
+}

+ 3
- 3
src/test/java/com/zipcodewilmington/bakery/BakeryApplicationTests.java 查看文件

@@ -9,8 +9,8 @@ import org.springframework.test.context.junit4.SpringRunner;
9 9
 @SpringBootTest
10 10
 public class BakeryApplicationTests {
11 11
 
12
-	@Test
13
-	public void contextLoads() {
14
-	}
12
+    @Test
13
+    public void contextLoads() {
14
+    }
15 15
 
16 16
 }