#29 Nick Satinover

Abierta
nsatinover desea fusionar 5 commits de nsatinover/CR-MicroLabs-Annotations-Bakery:master en master

BIN
lib/javax.ejb.jar Ver fichero


BIN
lib/javax.jms.jar Ver fichero


BIN
lib/javax.persistence.jar Ver fichero


BIN
lib/javax.resource.jar Ver fichero


BIN
lib/javax.servlet.jsp.jar Ver fichero


BIN
lib/javax.servlet.jsp.jstl.jar Ver fichero


BIN
lib/javax.transaction.jar Ver fichero


+ 18
- 7
pom.xml Ver fichero

@@ -11,12 +11,12 @@
11 11
 	<name>bakery</name>
12 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>1.5.11.RELEASE</version>
18
+        <relativePath/> <!-- lookup parent from repository -->
19
+    </parent>
20 20
 
21 21
 	<properties>
22 22
 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -25,6 +25,13 @@
25 25
 	</properties>
26 26
 
27 27
 	<dependencies>
28
+
29
+		<dependency>
30
+			<groupId>org.hsqldb</groupId>
31
+			<artifactId>hsqldb</artifactId>
32
+			<scope>runtime</scope>
33
+		</dependency>
34
+
28 35
 		<dependency>
29 36
 			<groupId>org.springframework.boot</groupId>
30 37
 			<artifactId>spring-boot-starter</artifactId>
@@ -50,7 +57,11 @@
50 57
 			<artifactId>spring-data-commons</artifactId>
51 58
 			<version>1.13.10.RELEASE</version>
52 59
 		</dependency>
53
-	</dependencies>
60
+        <dependency>
61
+            <groupId>org.springframework.boot</groupId>
62
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
63
+        </dependency>
64
+    </dependencies>
54 65
 
55 66
 	<build>
56 67
 		<plugins>

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/BakeryApplication.java Ver fichero

@@ -2,11 +2,22 @@ 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.boot.web.servlet.ServletRegistrationBean;
7
+import org.springframework.context.annotation.Bean;
5 8
 
9
+@EntityScan
6 10
 @SpringBootApplication
7 11
 public class BakeryApplication {
8 12
 
9 13
 	public static void main(String[] args) {
10 14
 		SpringApplication.run(BakeryApplication.class, args);
11 15
 	}
16
+
17
+//	@Bean
18
+//	ServletRegistrationBean h2servletRegistration(){
19
+//		ServletRegistrationBean registrationBean = new ServletRegistrationBean( new WebServlet());
20
+//		registrationBean.addUrlMappings("/console/*");
21
+//		return registrationBean;
22
+//	}
12 23
 }

+ 13
- 1
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Ver fichero

@@ -2,25 +2,36 @@ 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;
5 6
 import org.springframework.http.HttpStatus;
6 7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
7 9
 
10
+@RestController
8 11
 public class BakerController {
9 12
 
10 13
     private BakerRepository bakerRepository;
11 14
 
15
+    BakerController(@Autowired BakerRepository bakerRepository){
16
+        this.bakerRepository = bakerRepository;
17
+    }
18
+
19
+    @GetMapping("/baker")
12 20
     public ResponseEntity<Iterable<Baker>> index() {
13 21
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 22
     }
15 23
 
24
+    @GetMapping("/baker/{id}")
16 25
     public ResponseEntity<Baker> show(Long id) {
17 26
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 27
     }
19 28
 
29
+    @PostMapping("/baker")
20 30
     public ResponseEntity<Baker> create(Baker baker) {
21 31
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 32
     }
23 33
 
34
+    @RequestMapping(value = "/baker/{id}", method = RequestMethod.PUT)
24 35
     public ResponseEntity<Baker> update(Long id, Baker baker) {
25 36
         Baker foundBaker = bakerRepository.findOne(id);
26 37
 
@@ -30,7 +41,8 @@ public class BakerController {
30 41
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31 42
     }
32 43
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
44
+    @DeleteMapping("/baker/{id}")
45
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34 46
         this.bakerRepository.delete(id);
35 47
         return new ResponseEntity<>(true, HttpStatus.OK);
36 48
     }

+ 14
- 2
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Ver fichero

@@ -2,25 +2,36 @@ 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.*;
7 9
 
10
+@RestController
8 11
 public class MuffinController {
9 12
 
10 13
     private MuffinRepository muffinRepository;
11 14
 
15
+    public MuffinController(@Autowired MuffinRepository muffinRepository) {
16
+        this.muffinRepository = muffinRepository;
17
+    }
18
+
19
+    @GetMapping("/muffin")
12 20
     public ResponseEntity<Iterable<Muffin>> index() {
13 21
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 22
     }
15 23
 
24
+    @GetMapping("/muffin/{id}")
16 25
     public ResponseEntity<Muffin> show(Long id) {
17 26
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18 27
     }
19 28
 
29
+    @PostMapping("/muffin")
20 30
     public ResponseEntity<Muffin> create(Muffin muffin) {
21 31
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 32
     }
23 33
 
34
+    @RequestMapping(value = "/muffin/{id}", method = RequestMethod.PUT)
24 35
     public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
25 36
         Muffin foundMuffin = muffinRepository.findOne(id);
26 37
         foundMuffin.setFlavor(muffin.getFlavor());
@@ -28,9 +39,10 @@ public class MuffinController {
28 39
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 40
     }
30 41
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
42
+    @DeleteMapping("/muffin/{id}")
43
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 44
         this.muffinRepository.delete(id);
33 45
         return new ResponseEntity<>(true, HttpStatus.OK);
34 46
     }
35
-
47
+//change
36 48
 }

+ 9
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Ver fichero

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

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Ver fichero

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

+ 3
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Ver fichero

@@ -2,6 +2,9 @@ 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("beanBaker")
8
+@Repository("beanBaker")
6 9
 public interface BakerRepository extends CrudRepository<Baker, Long> {
7 10
 }

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Ver fichero

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

+ 4
- 0
src/main/resources/application-h2.properties Ver fichero

@@ -0,0 +1,4 @@
1
+spring.datasource.url=jdbc:h2:mem:testdb;Mode=Oracle
2
+spring.datasource.platform=h2
3
+spring.jpa.hibernate.ddl-auto=none
4
+spring.datasource.continue-on-error=true

+ 2
- 0
src/main/resources/application.properties Ver fichero

@@ -0,0 +1,2 @@
1
+spring.profiles.active=h2
2
+spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect