Browse Source

some annotations

mpierse 6 years ago
parent
commit
d367945bec

BIN
.DS_Store View File


+ 11
- 2
pom.xml View File

@@ -1,4 +1,5 @@
1
-<?xml version="1.0" encoding="UTF-8"?>
1
+
2
+ <?xml version="1.0" encoding="UTF-8"?>
2 3
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 4
 	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 5
 	<modelVersion>4.0.0</modelVersion>
@@ -50,7 +51,15 @@
50 51
 			<artifactId>spring-data-commons</artifactId>
51 52
 			<version>1.13.10.RELEASE</version>
52 53
 		</dependency>
53
-	</dependencies>
54
+        <dependency>
55
+            <groupId>org.springframework.boot</groupId>
56
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
57
+        </dependency>
58
+        <dependency>
59
+            <groupId>com.h2database</groupId>
60
+            <artifactId>h2</artifactId>
61
+        </dependency>
62
+    </dependencies>
54 63
 
55 64
 	<build>
56 65
 		<plugins>

+ 4
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java View File

@@ -2,7 +2,11 @@ package com.zipcodewilmington.bakery;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4 4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
+import org.springframework.boot.autoconfigure.domain.EntityScan;
6
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
5 7
 
8
+@EnableJpaRepositories
9
+@EntityScan
6 10
 @SpringBootApplication
7 11
 public class BakeryApplication {
8 12
 

+ 4
- 0
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java View File

@@ -4,7 +4,11 @@ import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5 5
 import org.springframework.http.HttpStatus;
6 6
 import org.springframework.http.ResponseEntity;
7
+import org.springframework.web.bind.annotation.RequestMapping;
8
+import org.springframework.web.bind.annotation.RestController;
7 9
 
10
+@RestController
11
+@RequestMapping
8 12
 public class BakerController {
9 13
 
10 14
     private BakerRepository bakerRepository;

+ 10
- 0
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

@@ -2,17 +2,27 @@ 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.web.bind.annotation.GetMapping;
9
+import org.springframework.web.bind.annotation.RequestMapping;
10
+import org.springframework.web.bind.annotation.RequestMethod;
11
+import org.springframework.web.bind.annotation.RestController;
7 12
 
13
+@RestController
14
+@RequestMapping
8 15
 public class MuffinController {
9 16
 
17
+    @Autowired
10 18
     private MuffinRepository muffinRepository;
11 19
 
20
+    @GetMapping(value="/polls/votes")
12 21
     public ResponseEntity<Iterable<Muffin>> index() {
13 22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 23
     }
15 24
 
25
+
16 26
     public ResponseEntity<Muffin> show(Long id) {
17 27
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 28
     }

+ 11
- 2
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java View File

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

+ 7
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java View File

@@ -1,9 +1,15 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import javax.persistence.Column;
4
+import javax.persistence.Entity;
5
+import javax.persistence.Id;
6
+
7
+@Entity
3 8
 public class Muffin {
4 9
 
10
+    @Id
5 11
     private Long id;
6
-
12
+    @Column
7 13
     private String flavor;
8 14
 
9 15
     public Muffin(String flavor) {

+ 1
- 0
src/main/resources/application.properties View File

@@ -0,0 +1 @@
1
+server.port=8081