Pārlūkot izejas kodu

Merge branch 'master' of https://git.zipcode.rocks/Cohort4.2/CR-MicroLabs-Annotations-Bakery

NiraParikh 5 gadus atpakaļ
vecāks
revīzija
3f2b337cb3

+ 57
- 50
pom.xml Parādīt failu

@@ -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>

+ 6
- 11
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Parādīt failu

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

+ 7
- 9
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Parādīt failu

@@ -19,9 +19,9 @@ public class MuffinController {
19 19
     public ResponseEntity<Iterable<Muffin>> index() {
20 20
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
21 21
     }
22
-    @GetMapping("/Baker/{id}")
23
-    public ResponseEntity<Muffin> show(@PathVariable(value = "id") Long id) {
24
-        return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
22
+
23
+    public ResponseEntity<Muffin> show(Long id) {
24
+        return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
25 25
     }
26 26
 
27 27
     @PostMapping("/Baker")
@@ -29,17 +29,15 @@ public class MuffinController {
29 29
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
30 30
     }
31 31
 
32
-    @PutMapping("/Baker/{id}")
33
-    public ResponseEntity<Muffin> update(@PathVariable(value = "id")Long id, Muffin muffin) {
34
-        Muffin foundMuffin = muffinRepository.findOne(id);
32
+    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
33
+        Muffin foundMuffin = muffinRepository.findById(id).get();
35 34
         foundMuffin.setFlavor(muffin.getFlavor());
36 35
 
37 36
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
38 37
     }
39 38
 
40
-    @DeleteMapping("/Baker/{id}")
41
-    public ResponseEntity<Boolean> destroy(@PathVariable(value = "id")Long id) {
42
-        this.muffinRepository.delete(id);
39
+    public ResponseEntity<Boolean> destroy(Long id) {
40
+        this.muffinRepository.deleteById(id);
43 41
         return new ResponseEntity<>(true, HttpStatus.OK);
44 42
     }
45 43
 

+ 0
- 3
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Parādīt failu

@@ -7,9 +7,6 @@ import javax.persistence.Id;
7 7
 
8 8
 @Entity
9 9
 public class Muffin {
10
-
11
-    @Id
12
-    @GeneratedValue(strategy = GenerationType.AUTO)
13 10
     private Long id;
14 11
 
15 12
     private String flavor;

+ 1
- 1
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Parādīt failu

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

+ 1
- 1
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Parādīt failu

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