Yesoda Sanka 5 anni fa
parent
commit
c77a98b590

+ 62
- 51
pom.xml Vedi File

1
 <?xml version="1.0" encoding="UTF-8"?>
1
 <?xml version="1.0" encoding="UTF-8"?>
2
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
 </project>
76
 </project>

+ 13
- 17
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Vedi File

6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
8
 import org.springframework.stereotype.Controller;
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
 @RestController
11
 @RestController
15
 public class BakerController {
12
 public class BakerController {
16
 
13
 
17
-
18
     @Autowired
14
     @Autowired
19
     private BakerRepository bakerRepository;
15
     private BakerRepository bakerRepository;
20
 
16
 
21
-
17
+    @RequestMapping (value="/baker", method=RequestMethod.GET )
22
     public ResponseEntity<Iterable<Baker>> index() {
18
     public ResponseEntity<Iterable<Baker>> index() {
23
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
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
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
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
         foundBaker.setName(baker.getName());
33
         foundBaker.setName(baker.getName());
38
         foundBaker.setSpecialty(baker.getSpecialty());
34
         foundBaker.setSpecialty(baker.getSpecialty());
39
 
35
 
40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
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
         return new ResponseEntity<>(true, HttpStatus.OK);
41
         return new ResponseEntity<>(true, HttpStatus.OK);
46
     }
42
     }
47
 }
43
 }

+ 14
- 10
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Vedi File

6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
8
 import org.springframework.stereotype.Controller;
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
 @RestController
11
 @RestController
13
 public class MuffinController {
12
 public class MuffinController {
15
     @Autowired
14
     @Autowired
16
     private MuffinRepository muffinRepository;
15
     private MuffinRepository muffinRepository;
17
 
16
 
17
+
18
+    @RequestMapping(value="/muffin",method= RequestMethod.GET   )
18
     public ResponseEntity<Iterable<Muffin>> index() {
19
     public ResponseEntity<Iterable<Muffin>> index() {
19
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
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
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
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
         foundMuffin.setFlavor(muffin.getFlavor());
36
         foundMuffin.setFlavor(muffin.getFlavor());
33
 
37
 
34
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
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
         return new ResponseEntity<>(true, HttpStatus.OK);
43
         return new ResponseEntity<>(true, HttpStatus.OK);
40
     }
44
     }
41
 
45
 

+ 14
- 3
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Vedi File

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

+ 12
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Vedi File

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

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Vedi File

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

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Vedi File

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

+ 1
- 1
src/main/resources/application.properties Vedi File

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