소스 검색

Lab started

NiraParikh 5 년 전
부모
커밋
0f16110bcd

BIN
.DS_Store 파일 보기


+ 5
- 1
pom.xml 파일 보기

@@ -50,7 +50,11 @@
50 50
 			<artifactId>spring-data-commons</artifactId>
51 51
 			<version>1.13.10.RELEASE</version>
52 52
 		</dependency>
53
-	</dependencies>
53
+        <dependency>
54
+            <groupId>org.springframework.boot</groupId>
55
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
56
+        </dependency>
57
+    </dependencies>
54 58
 
55 59
 	<build>
56 60
 		<plugins>

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

@@ -2,26 +2,34 @@ 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
 
13
+    @Autowired
10 14
     private BakerRepository bakerRepository;
11 15
 
16
+    @GetMapping("/Baker")
12 17
     public ResponseEntity<Iterable<Baker>> index() {
13 18
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14 19
     }
15 20
 
16
-    public ResponseEntity<Baker> show(Long id) {
21
+    @GetMapping("/Baker/{id}")
22
+    public ResponseEntity<Baker> show(@PathVariable(value = "id") Long id) {
17 23
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18 24
     }
19 25
 
26
+    @PostMapping("/Baker")
20 27
     public ResponseEntity<Baker> create(Baker baker) {
21 28
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22 29
     }
23 30
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
31
+    @PutMapping("/Baker/{id}")
32
+    public ResponseEntity<Baker> update(@PathVariable(value = "id")Long id, Baker baker) {
25 33
         Baker foundBaker = bakerRepository.findOne(id);
26 34
 
27 35
         foundBaker.setName(baker.getName());
@@ -30,7 +38,8 @@ public class BakerController {
30 38
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31 39
     }
32 40
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
41
+    @DeleteMapping("/Baker/{id}")
42
+    public ResponseEntity<Boolean> destroy(@PathVariable(value = "id")Long id) {
34 43
         this.bakerRepository.delete(id);
35 44
         return new ResponseEntity<>(true, HttpStatus.OK);
36 45
     }

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

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

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

@@ -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 파일 보기

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

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

@@ -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.web.bind.annotation.RestController;
5 6
 
7
+@RestController
6 8
 public interface BakerRepository extends CrudRepository<Baker, Long> {
7 9
 }

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

@@ -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.web.bind.annotation.RestController;
5 6
 
7
+@RestController
6 8
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
7 9
 }