2 Commits

Author SHA1 Message Date
  Jennifer Chao 689e575e86 fixed the pom.xml 5 years ago
  Jennifer Chao e9f8ff7d5a aaaaa 5 years ago

+ 82
- 60
pom.xml View File

@@ -1,65 +1,87 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
-	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
-	<modelVersion>4.0.0</modelVersion>
5
-
6
-	<groupId>com.zipcodewilmington</groupId>
7
-	<artifactId>bakery</artifactId>
8
-	<version>0.0.1-SNAPSHOT</version>
9
-	<packaging>jar</packaging>
10
-
11
-	<name>bakery</name>
12
-	<description>Demo project for Spring Boot</description>
13
-
14
-	<parent>
15
-		<groupId>org.springframework.boot</groupId>
16
-		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
18
-		<relativePath/> <!-- lookup parent from repository -->
19
-	</parent>
20
-
21
-	<properties>
22
-		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
-		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
-		<java.version>1.8</java.version>
25
-	</properties>
26
-
27
-	<dependencies>
28
-		<dependency>
29
-			<groupId>org.springframework.boot</groupId>
30
-			<artifactId>spring-boot-starter</artifactId>
31
-		</dependency>
32
-
33
-		<dependency>
34
-			<groupId>org.springframework.boot</groupId>
35
-			<artifactId>spring-boot-starter-data-rest</artifactId>
36
-		</dependency>
37
-
38
-		<dependency>
39
-			<groupId>org.springframework.boot</groupId>
40
-			<artifactId>spring-boot-starter-web</artifactId>
41
-		</dependency>
42
-
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.springframework.data</groupId>
50
-			<artifactId>spring-data-commons</artifactId>
51
-			<version>1.13.10.RELEASE</version>
52
-		</dependency>
53
-	</dependencies>
54
-
55
-	<build>
56
-		<plugins>
57
-			<plugin>
58
-				<groupId>org.springframework.boot</groupId>
59
-				<artifactId>spring-boot-maven-plugin</artifactId>
60
-			</plugin>
61
-		</plugins>
62
-	</build>
3
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
+    <modelVersion>4.0.0</modelVersion>
5
+
6
+    <groupId>com.zipcodewilmington</groupId>
7
+    <artifactId>bakery</artifactId>
8
+    <version>0.0.1-SNAPSHOT</version>
9
+    <packaging>jar</packaging>
10
+
11
+    <name>bakery</name>
12
+    <description>Demo project for Spring Boot</description>
13
+
14
+    <parent>
15
+        <groupId>org.springframework.boot</groupId>
16
+        <artifactId>spring-boot-starter-parent</artifactId>
17
+        <version>1.5.11.RELEASE</version>
18
+        <relativePath/> <!-- lookup parent from repository -->
19
+    </parent>
20
+
21
+    <properties>
22
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24
+        <java.version>1.8</java.version>
25
+    </properties>
26
+
27
+    <dependencies>
28
+        <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
29
+        <dependency>
30
+            <groupId>org.hsqldb</groupId>
31
+            <artifactId>hsqldb</artifactId>
32
+            <scope>runtime</scope>
33
+        </dependency>
34
+
35
+        <dependency>
36
+            <groupId>org.springframework.boot</groupId>
37
+            <artifactId>spring-boot-starter</artifactId>
38
+        </dependency>
39
+
40
+        <dependency>
41
+            <groupId>org.springframework.boot</groupId>
42
+            <artifactId>spring-boot-starter-data-rest</artifactId>
43
+        </dependency>
44
+
45
+        <dependency>
46
+            <groupId>org.springframework.boot</groupId>
47
+            <artifactId>spring-boot-starter-web</artifactId>
48
+        </dependency>
49
+
50
+        <dependency>
51
+            <groupId>org.springframework.boot</groupId>
52
+            <artifactId>spring-boot-starter-test</artifactId>
53
+            <scope>test</scope>
54
+        </dependency>
55
+
56
+        <dependency>
57
+            <groupId>org.springframework.data</groupId>
58
+            <artifactId>spring-data-commons</artifactId>
59
+            <version>1.13.10.RELEASE</version>
60
+        </dependency>
61
+
62
+        <dependency>
63
+            <groupId>org.springframework.boot</groupId>
64
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
65
+        </dependency>
66
+
67
+        <!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
68
+        <dependency>
69
+            <groupId>com.h2database</groupId>
70
+            <artifactId>h2</artifactId>
71
+            <version>1.4.197</version>
72
+            <scope>test</scope>
73
+        </dependency>
74
+
75
+    </dependencies>
76
+
77
+    <build>
78
+        <plugins>
79
+            <plugin>
80
+                <groupId>org.springframework.boot</groupId>
81
+                <artifactId>spring-boot-maven-plugin</artifactId>
82
+            </plugin>
83
+        </plugins>
84
+    </build>
63 85
 
64 86
 
65 87
 </project>

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

@@ -2,26 +2,39 @@ 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.*;
7 9
 
10
+import java.lang.reflect.Array;
11
+import java.util.*;
12
+import java.util.stream.Collectors;
13
+import java.util.stream.Stream;
14
+
15
+@RestController
8 16
 public class BakerController {
9 17
 
18
+    @Autowired
10 19
     private BakerRepository bakerRepository;
11 20
 
21
+    @GetMapping(path = "/bakers")
12 22
     public ResponseEntity<Iterable<Baker>> index() {
13 23
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 24
     }
15 25
 
16
-    public ResponseEntity<Baker> show(Long id) {
26
+    @GetMapping(path = "/bakers/{id}")
27
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17 28
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 29
     }
19 30
 
31
+    @PostMapping(path = "/bakers")
20 32
     public ResponseEntity<Baker> create(Baker baker) {
21 33
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 34
     }
23 35
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
36
+    @PutMapping(path = "/bakers/{id}")
37
+    public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
25 38
         Baker foundBaker = bakerRepository.findOne(id);
26 39
 
27 40
         foundBaker.setName(baker.getName());
@@ -30,8 +43,9 @@ public class BakerController {
30 43
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31 44
     }
32 45
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
46
+    @DeleteMapping(path = "/bakers/{id}")
47
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34 48
         this.bakerRepository.delete(id);
35 49
         return new ResponseEntity<>(true, HttpStatus.OK);
36 50
     }
37
-}
51
+}

+ 12
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

@@ -2,33 +2,42 @@ 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
+    @GetMapping(path = "/muffins")
12 17
     public ResponseEntity<Iterable<Muffin>> index() {
13 18
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 19
     }
15 20
 
16
-    public ResponseEntity<Muffin> show(Long id) {
21
+    @GetMapping(path = "/muffins/{id}")
22
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 23
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 24
     }
19 25
 
26
+    @PostMapping(path = "/muffins")
20 27
     public ResponseEntity<Muffin> create(Muffin muffin) {
21 28
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 29
     }
23 30
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
31
+    @PutMapping(path = "/muffins/{id}")
32
+    public ResponseEntity<Muffin> update(@PathVariable Long id, Muffin muffin) {
25 33
         Muffin foundMuffin = muffinRepository.findOne(id);
26 34
         foundMuffin.setFlavor(muffin.getFlavor());
27 35
 
28 36
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 37
     }
30 38
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
39
+    @DeleteMapping(path = "/muffins/{id}")
40
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 41
         this.muffinRepository.delete(id);
33 42
         return new ResponseEntity<>(true, HttpStatus.OK);
34 43
     }

+ 10
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java View File

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

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

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

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

@@ -2,6 +2,10 @@ 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> {
7 11
 }

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

@@ -2,6 +2,10 @@ 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 = "muffins", path = "muffins")
6 10
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7 11
 }