3 次代码提交

作者 SHA1 备注 提交日期
  NiraParikh 898be085a3 Done 5 年前
  NiraParikh 3f2b337cb3 Merge branch 'master' of https://git.zipcode.rocks/Cohort4.2/CR-MicroLabs-Annotations-Bakery 5 年前
  Leon 1356254de5 updated dependencies 5 年前

+ 57
- 50
pom.xml 查看文件

@@ -1,69 +1,76 @@
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>
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 5
 
6
-	<groupId>com.zipcodewilmington</groupId>
7
-	<artifactId>bakery</artifactId>
8
-	<version>0.0.1-SNAPSHOT</version>
9
-	<packaging>jar</packaging>
6
+    <groupId>com.zipcodewilmington</groupId>
7
+    <artifactId>bakery</artifactId>
8
+    <version>0.0.1-SNAPSHOT</version>
9
+    <packaging>jar</packaging>
10 10
 
11
-	<name>bakery</name>
12
-	<description>Demo project for Spring Boot</description>
11
+    <name>bakery</name>
12
+    <description>Demo project for Spring Boot</description>
13 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>
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 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>
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 26
 
27
-	<dependencies>
28
-		<dependency>
29
-			<groupId>org.springframework.boot</groupId>
30
-			<artifactId>spring-boot-starter</artifactId>
31
-		</dependency>
27
+    <dependencies>
28
+        <dependency>
29
+            <groupId>org.springframework.boot</groupId>
30
+            <artifactId>spring-boot-starter</artifactId>
31
+        </dependency>
32 32
 
33
-		<dependency>
34
-			<groupId>org.springframework.boot</groupId>
35
-			<artifactId>spring-boot-starter-data-rest</artifactId>
36
-		</dependency>
33
+        <dependency>
34
+            <groupId>org.springframework.boot</groupId>
35
+            <artifactId>spring-boot-starter-data-rest</artifactId>
36
+        </dependency>
37 37
 
38
-		<dependency>
39
-			<groupId>org.springframework.boot</groupId>
40
-			<artifactId>spring-boot-starter-web</artifactId>
41
-		</dependency>
38
+        <dependency>
39
+            <groupId>org.springframework.boot</groupId>
40
+            <artifactId>spring-boot-starter-web</artifactId>
41
+        </dependency>
42 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>
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
+        </dependency>
52
+        <dependency>
53
+            <groupId>org.springframework.boot</groupId>
54
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
55
+        </dependency>
56
+        <dependency>
57
+            <groupId>com.h2database</groupId>
58
+            <artifactId>h2</artifactId>
59
+        </dependency>
53 60
         <dependency>
54 61
             <groupId>org.springframework.boot</groupId>
55 62
             <artifactId>spring-boot-starter-data-jpa</artifactId>
56 63
         </dependency>
57 64
     </dependencies>
58 65
 
59
-	<build>
60
-		<plugins>
61
-			<plugin>
62
-				<groupId>org.springframework.boot</groupId>
63
-				<artifactId>spring-boot-maven-plugin</artifactId>
64
-			</plugin>
65
-		</plugins>
66
-	</build>
66
+    <build>
67
+        <plugins>
68
+            <plugin>
69
+                <groupId>org.springframework.boot</groupId>
70
+                <artifactId>spring-boot-maven-plugin</artifactId>
71
+            </plugin>
72
+        </plugins>
73
+    </build>
67 74
 
68 75
 
69 76
 </project>

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

@@ -7,30 +7,37 @@ import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8 8
 import org.springframework.web.bind.annotation.*;
9 9
 
10
+import javax.persistence.PostUpdate;
11
+
10 12
 @RestController
11 13
 public class BakerController {
12 14
 
13
-    @Autowired
14 15
     private BakerRepository bakerRepository;
15 16
 
16
-    @GetMapping("/Baker")
17
+    @Autowired
18
+    public BakerController(BakerRepository bakerRepository) {
19
+        this.bakerRepository = bakerRepository;
20
+    }
21
+
22
+
23
+    @GetMapping("/Baker/")
17 24
     public ResponseEntity<Iterable<Baker>> index() {
18 25
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
19 26
     }
20 27
 
21 28
     @GetMapping("/Baker/{id}")
22
-    public ResponseEntity<Baker> show(@PathVariable(value = "id") Long id) {
23
-        return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
29
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
30
+        return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
24 31
     }
25 32
 
26
-    @PostMapping("/Baker")
27
-    public ResponseEntity<Baker> create(Baker baker) {
33
+    @PostMapping("/Baker/")
34
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
28 35
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
29 36
     }
30 37
 
31 38
     @PutMapping("/Baker/{id}")
32
-    public ResponseEntity<Baker> update(@PathVariable(value = "id")Long id, Baker baker) {
33
-        Baker foundBaker = bakerRepository.findOne(id);
39
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
40
+        Baker foundBaker = bakerRepository.findById(id).get();
34 41
 
35 42
         foundBaker.setName(baker.getName());
36 43
         foundBaker.setSpecialty(baker.getSpecialty());
@@ -39,8 +46,8 @@ public class BakerController {
39 46
     }
40 47
 
41 48
     @DeleteMapping("/Baker/{id}")
42
-    public ResponseEntity<Boolean> destroy(@PathVariable(value = "id")Long id) {
43
-        this.bakerRepository.delete(id);
49
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
50
+        this.bakerRepository.delete(this.bakerRepository.findById(id).get());
44 51
         return new ResponseEntity<>(true, HttpStatus.OK);
45 52
     }
46 53
 }

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

@@ -3,43 +3,47 @@ package com.zipcodewilmington.bakery.Controllers;
3 3
 import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.context.annotation.Bean;
7 6
 import org.springframework.http.HttpStatus;
8 7
 import org.springframework.http.ResponseEntity;
9
-import org.springframework.stereotype.Repository;
10 8
 import org.springframework.web.bind.annotation.*;
11 9
 
12 10
 @RestController
13 11
 public class MuffinController {
14 12
 
15
-    @Autowired
16 13
     private MuffinRepository muffinRepository;
17 14
 
18
-    @GetMapping("/Baker")
15
+    @Autowired
16
+    public MuffinController(MuffinRepository muffinRepository) {
17
+        this.muffinRepository = muffinRepository;
18
+    }
19
+
20
+
21
+    @GetMapping("/Muffin/")
19 22
     public ResponseEntity<Iterable<Muffin>> index() {
20 23
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
21 24
     }
22
-    @GetMapping("/Baker/{id}")
23
-    public ResponseEntity<Muffin> show(@PathVariable(value = "id") Long id) {
24
-        return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
25
+
26
+    @GetMapping("/Muffin/{id}")
27
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
28
+        return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
25 29
     }
26 30
 
27
-    @PostMapping("/Baker")
28
-    public ResponseEntity<Muffin> create(Muffin muffin) {
31
+    @PostMapping("/Muffin/")
32
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
29 33
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
30 34
     }
31 35
 
32
-    @PutMapping("/Baker/{id}")
33
-    public ResponseEntity<Muffin> update(@PathVariable(value = "id")Long id, Muffin muffin) {
34
-        Muffin foundMuffin = muffinRepository.findOne(id);
36
+    @PutMapping("/Muffin/{id}")
37
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
38
+        Muffin foundMuffin = muffinRepository.findById(id).get();
35 39
         foundMuffin.setFlavor(muffin.getFlavor());
36 40
 
37 41
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
38 42
     }
39 43
 
40
-    @DeleteMapping("/Baker/{id}")
41
-    public ResponseEntity<Boolean> destroy(@PathVariable(value = "id")Long id) {
42
-        this.muffinRepository.delete(id);
44
+    @DeleteMapping("/Muffin/{id}")
45
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id){
46
+        this.muffinRepository.delete(this.muffinRepository.findById(id).get());
43 47
         return new ResponseEntity<>(true, HttpStatus.OK);
44 48
     }
45 49
 

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

@@ -1,23 +1,26 @@
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;
3
+import javax.persistence.*;
7 4
 
8 5
 @Entity
9 6
 public class Baker {
10 7
 
11 8
     @Id
12 9
     @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column(name = "id")
13 11
     private Long id;
14 12
 
13
+    @Column(name = "name")
15 14
     private String name;
16 15
 
16
+    @Column(name = "employeeId")
17 17
     private String employeeId;
18 18
 
19
+    @Column(name = "specialty")
19 20
     private String specialty;
20 21
 
22
+    public Baker() {}
23
+
21 24
     public Baker(String name, String employeeId, String specialty) {
22 25
         this.name = name;
23 26
         this.employeeId = employeeId;

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

@@ -1,19 +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.GenerationType;
6
-import javax.persistence.Id;
3
+import javax.persistence.*;
7 4
 
8 5
 @Entity
9 6
 public class Muffin {
10 7
 
11 8
     @Id
12 9
     @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column (name = "id")
13 11
     private Long id;
14 12
 
13
+    @Column (name = "flavor")
15 14
     private String flavor;
16 15
 
16
+    public Muffin() {}
17
+
17 18
     public Muffin(String flavor) {
18 19
         this.flavor = flavor;
19 20
     }

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

@@ -2,8 +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.web.bind.annotation.RestController;
5
+import org.springframework.stereotype.Repository;
6 6
 
7
-@RestController
7
+@Repository
8 8
 public interface BakerRepository extends CrudRepository<Baker, Long> {
9 9
 }

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

@@ -2,8 +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.web.bind.annotation.RestController;
5
+import org.springframework.stereotype.Repository;
6 6
 
7
-@RestController
7
+@Repository
8 8
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
9 9
 }