Michelle DiMarino 5 년 전
부모
커밋
50fb632548

+ 7
- 7
pom.xml 파일 보기

@@ -25,11 +25,6 @@
25 25
 	</properties>
26 26
 
27 27
 	<dependencies>
28
-		<dependency>
29
-			<groupId>org.hsqldb</groupId>
30
-			<artifactId>hsqldb</artifactId>
31
-			<scope>runtime</scope>
32
-		</dependency>
33 28
 
34 29
 		<dependency>
35 30
 			<groupId>org.springframework.boot</groupId>
@@ -59,9 +54,14 @@
59 54
         <dependency>
60 55
             <groupId>org.springframework.boot</groupId>
61 56
             <artifactId>spring-boot-starter-data-jpa</artifactId>
62
-            <version>RELEASE</version>
63
-            <scope>compile</scope>
64 57
         </dependency>
58
+
59
+		<dependency>
60
+			<groupId>org.hsqldb</groupId>
61
+			<artifactId>hsqldb</artifactId>
62
+			<scope>runtime</scope>
63
+		</dependency>
64
+
65 65
     </dependencies>
66 66
 
67 67
 	<build>

+ 13
- 22
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java 파일 보기

@@ -3,44 +3,35 @@ package com.zipcodewilmington.bakery.Controllers;
3 3
 import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6
-import org.springframework.context.annotation.Bean;
7 6
 import org.springframework.http.HttpStatus;
8 7
 import org.springframework.http.ResponseEntity;
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
+import org.springframework.web.bind.annotation.*;
9
+
10
+
11
+@RestController
21 12
 public class BakerController {
22 13
 
23 14
     @Autowired
24 15
     private BakerRepository bakerRepository;
25 16
 
26 17
 
27
-    @GetMapping(path = "/baker")
18
+    @GetMapping("/baker")
28 19
     public ResponseEntity<Iterable<Baker>> index() {
29 20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
30 21
     }
31 22
 
32
-    @GetMapping(path = "/baker/{id}")
33
-    public ResponseEntity<Baker> show(Long id) {
23
+    @GetMapping("/baker/{id}")
24
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
34 25
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
35 26
     }
36 27
 
37
-    @PostMapping(path = "/baker")
38
-    public ResponseEntity<Baker> create(Baker baker) {
28
+    @PostMapping("/baker")
29
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
39 30
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
40 31
     }
41 32
 
42
-    @PutMapping(path = "/baker")
43
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
33
+    @PutMapping("/baker/{id}")
34
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
44 35
         Baker foundBaker = bakerRepository.findOne(id);
45 36
 
46 37
         foundBaker.setName(baker.getName());
@@ -49,8 +40,8 @@ public class BakerController {
49 40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
50 41
     }
51 42
 
52
-    @DeleteMapping(path = "/baker")
53
-    public ResponseEntity<Boolean> destroy(Long id) {
43
+    @DeleteMapping("/baker/{id}")
44
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
54 45
         this.bakerRepository.delete(id);
55 46
         return new ResponseEntity<>(true, HttpStatus.OK);
56 47
     }

+ 11
- 14
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java 파일 보기

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

+ 0
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java 파일 보기

@@ -1,6 +1,5 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
-import org.springframework.data.annotation.Id;
4 3
 
5 4
 import javax.persistence.*;
6 5
 

+ 0
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java 파일 보기

@@ -1,6 +1,5 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
-import org.springframework.data.annotation.Id;
4 3
 
5 4
 import javax.persistence.*;
6 5
 

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java 파일 보기

@@ -2,6 +2,7 @@ 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.data.rest.core.annotation.RepositoryRestResource;
5 6
 import org.springframework.stereotype.Repository;
6 7
 
7 8
 @Repository

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java 파일 보기

@@ -2,6 +2,7 @@ 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.data.rest.core.annotation.RepositoryRestResource;
5 6
 import org.springframework.stereotype.Repository;
6 7
 
7 8
 @Repository