Michelle DiMarino 5 jaren geleden
bovenliggende
commit
060b956985

BIN
.DS_Store Bestand weergeven


+ 14
- 2
pom.xml Bestand weergeven

@@ -14,7 +14,7 @@
14 14
 	<parent>
15 15
 		<groupId>org.springframework.boot</groupId>
16 16
 		<artifactId>spring-boot-starter-parent</artifactId>
17
-		<version>2.0.4.RELEASE</version>
17
+		<version>1.5.11.RELEASE</version>
18 18
 		<relativePath/> <!-- lookup parent from repository -->
19 19
 	</parent>
20 20
 
@@ -26,6 +26,12 @@
26 26
 
27 27
 	<dependencies>
28 28
 		<dependency>
29
+			<groupId>org.hsqldb</groupId>
30
+			<artifactId>hsqldb</artifactId>
31
+			<scope>runtime</scope>
32
+		</dependency>
33
+
34
+		<dependency>
29 35
 			<groupId>org.springframework.boot</groupId>
30 36
 			<artifactId>spring-boot-starter</artifactId>
31 37
 		</dependency>
@@ -50,7 +56,13 @@
50 56
 			<artifactId>spring-data-commons</artifactId>
51 57
 			<version>1.13.10.RELEASE</version>
52 58
 		</dependency>
53
-	</dependencies>
59
+        <dependency>
60
+            <groupId>org.springframework.boot</groupId>
61
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
62
+            <version>RELEASE</version>
63
+            <scope>compile</scope>
64
+        </dependency>
65
+    </dependencies>
54 66
 
55 67
 	<build>
56 68
 		<plugins>

+ 5
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java Bestand weergeven

@@ -3,10 +3,15 @@ package com.zipcodewilmington.bakery;
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 5
 
6
+import javax.persistence.EntityManager;
7
+import javax.persistence.EntityManagerFactory;
8
+import javax.persistence.Persistence;
9
+
6 10
 @SpringBootApplication
7 11
 public class BakeryApplication {
8 12
 
9 13
 	public static void main(String[] args) {
14
+
10 15
 		SpringApplication.run(BakeryApplication.class, args);
11 16
 	}
12 17
 }

+ 21
- 1
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Bestand weergeven

@@ -2,25 +2,44 @@ 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;
6
+import org.springframework.context.annotation.Bean;
5 7
 import org.springframework.http.HttpStatus;
6 8
 import org.springframework.http.ResponseEntity;
7
-
9
+import org.springframework.orm.jpa.JpaVendorAdapter;
10
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
11
+import org.springframework.stereotype.Controller;
12
+import org.springframework.web.bind.annotation.DeleteMapping;
13
+import org.springframework.web.bind.annotation.GetMapping;
14
+import org.springframework.web.bind.annotation.PostMapping;
15
+import org.springframework.web.bind.annotation.PutMapping;
16
+
17
+import javax.activation.DataSource;
18
+import javax.persistence.EntityManagerFactory;
19
+
20
+@Controller
8 21
 public class BakerController {
9 22
 
23
+    @Autowired
10 24
     private BakerRepository bakerRepository;
11 25
 
26
+
27
+    @GetMapping(path = "/baker")
12 28
     public ResponseEntity<Iterable<Baker>> index() {
13 29
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 30
     }
15 31
 
32
+    @GetMapping(path = "/baker/{id}")
16 33
     public ResponseEntity<Baker> show(Long id) {
17 34
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 35
     }
19 36
 
37
+    @PostMapping(path = "/baker")
20 38
     public ResponseEntity<Baker> create(Baker baker) {
21 39
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 40
     }
23 41
 
42
+    @PutMapping(path = "/baker")
24 43
     public ResponseEntity<Baker> update(Long id, Baker baker) {
25 44
         Baker foundBaker = bakerRepository.findOne(id);
26 45
 
@@ -30,6 +49,7 @@ public class BakerController {
30 49
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31 50
     }
32 51
 
52
+    @DeleteMapping(path = "/baker")
33 53
     public ResponseEntity<Boolean> destroy(Long id) {
34 54
         this.bakerRepository.delete(id);
35 55
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 17
- 0
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Bestand weergeven

@@ -2,25 +2,41 @@ 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.stereotype.Controller;
9
+import org.springframework.web.bind.annotation.DeleteMapping;
10
+import org.springframework.web.bind.annotation.GetMapping;
11
+import org.springframework.web.bind.annotation.PostMapping;
12
+import org.springframework.web.bind.annotation.PutMapping;
7 13
 
14
+import javax.persistence.EntityManager;
15
+import javax.persistence.EntityManagerFactory;
16
+import javax.persistence.Persistence;
17
+
18
+@Controller
8 19
 public class MuffinController {
9 20
 
21
+    @Autowired
10 22
     private MuffinRepository muffinRepository;
11 23
 
24
+    @GetMapping(path = "/muffin")
12 25
     public ResponseEntity<Iterable<Muffin>> index() {
13 26
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 27
     }
15 28
 
29
+    @GetMapping(path = "/muffin/{id}")
16 30
     public ResponseEntity<Muffin> show(Long id) {
17 31
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 32
     }
19 33
 
34
+    @PostMapping(path = "/muffin")
20 35
     public ResponseEntity<Muffin> create(Muffin muffin) {
21 36
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 37
     }
23 38
 
39
+    @PutMapping(path = "/muffin")
24 40
     public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
25 41
         Muffin foundMuffin = muffinRepository.findOne(id);
26 42
         foundMuffin.setFlavor(muffin.getFlavor());
@@ -28,6 +44,7 @@ public class MuffinController {
28 44
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 45
     }
30 46
 
47
+    @DeleteMapping(path = "/muffin")
31 48
     public ResponseEntity<Boolean> destroy(Long id) {
32 49
         this.muffinRepository.delete(id);
33 50
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Bestand weergeven

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

+ 9
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Bestand weergeven

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

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Bestand weergeven

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

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Bestand weergeven

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