Yesoda Sanka 5 gadus atpakaļ
vecāks
revīzija
c77a98b590

+ 62
- 51
pom.xml Parādīt failu

@@ -1,65 +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>
53
-	</dependencies>
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>
60
+        <dependency>
61
+            <groupId>org.springframework.boot</groupId>
62
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
63
+        </dependency>
64
+    </dependencies>
54 65
 
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>
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>
63 74
 
64 75
 
65 76
 </project>

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

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

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

@@ -6,8 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
6 6
 import org.springframework.http.HttpStatus;
7 7
 import org.springframework.http.ResponseEntity;
8 8
 import org.springframework.stereotype.Controller;
9
-import org.springframework.web.bind.annotation.GetMapping;
10
-import org.springframework.web.bind.annotation.RestController;
9
+import org.springframework.web.bind.annotation.*;
11 10
 
12 11
 @RestController
13 12
 public class MuffinController {
@@ -15,27 +14,32 @@ public class MuffinController {
15 14
     @Autowired
16 15
     private MuffinRepository muffinRepository;
17 16
 
17
+
18
+    @RequestMapping(value="/muffin",method= RequestMethod.GET   )
18 19
     public ResponseEntity<Iterable<Muffin>> index() {
19 20
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
20 21
     }
21 22
 
22
-    public ResponseEntity<Muffin> show(Long id) {
23
-        return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
23
+    @RequestMapping(value="/muffin/{id}",method= RequestMethod.GET   )
24
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
25
+        return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
24 26
     }
25 27
 
26
-    public ResponseEntity<Muffin> create(Muffin muffin) {
28
+    @RequestMapping(value="/muffin",method= RequestMethod.POST)
29
+    public ResponseEntity<Muffin> create(@RequestBody   Muffin muffin) {
27 30
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
28 31
     }
29 32
 
30
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
31
-        Muffin foundMuffin = muffinRepository.findOne(id);
33
+    @RequestMapping(value="/muffin/{id}",method= RequestMethod.PUT)
34
+    public ResponseEntity<Muffin> update(@PathVariable  Long id, @RequestBody Muffin muffin) {
35
+        Muffin foundMuffin = muffinRepository.findById(id).get();
32 36
         foundMuffin.setFlavor(muffin.getFlavor());
33 37
 
34 38
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
35 39
     }
36
-
37
-    public ResponseEntity<Boolean> destroy(Long id) {
38
-        this.muffinRepository.delete(id);
40
+    @RequestMapping(value="/muffin/{id}",method= RequestMethod.DELETE)
41
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
42
+        this.muffinRepository.delete (this.muffinRepository.findById(id).get()) ;
39 43
         return new ResponseEntity<>(true, HttpStatus.OK);
40 44
     }
41 45
 

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

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

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

@@ -1,12 +1,24 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import javax.persistence.*;
4
+
5
+@Entity
3 6
 public class Muffin {
4 7
 
8
+    @Id
9
+    @GeneratedValue (strategy = GenerationType.AUTO)
10
+
11
+    @Column(name="id")
5 12
     private Long id;
6 13
 
14
+    @Column(name="flavor")
7 15
     private String flavor;
8 16
 
17
+    public Muffin() {
18
+    }
19
+
9 20
     public Muffin(String flavor) {
21
+
10 22
         this.flavor = flavor;
11 23
     }
12 24
 

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

@@ -4,7 +4,10 @@ import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
7 9
 @Repository
8 10
 public interface BakerRepository extends CrudRepository<Baker, Long> {
9 11
 
12
+
10 13
 }

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

@@ -4,7 +4,10 @@ import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6 6
 
7
+import java.util.List;
8
+
7 9
 @Repository
8 10
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
9 11
 
12
+
10 13
 }

+ 1
- 1
src/main/resources/application.properties Parādīt failu

@@ -1 +1 @@
1
-server.port:8082
1
+server.port:8080