Browse Source

Annotations added

Lauren Green 6 years ago
parent
commit
fe83ecd23a

+ 5
- 1
pom.xml View File

50
 			<artifactId>spring-data-commons</artifactId>
50
 			<artifactId>spring-data-commons</artifactId>
51
 			<version>1.13.10.RELEASE</version>
51
 			<version>1.13.10.RELEASE</version>
52
 		</dependency>
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
 	<build>
59
 	<build>
56
 		<plugins>
60
 		<plugins>

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

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Baker;
3
 import com.zipcodewilmington.bakery.Models.Baker;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
7
 
9
 
10
+@RestController
8
 public class BakerController {
11
 public class BakerController {
9
 
12
 
13
+    @Autowired
10
     private BakerRepository bakerRepository;
14
     private BakerRepository bakerRepository;
11
 
15
 
16
+    @RequestMapping(value="/bakers", method= RequestMethod.GET)
12
     public ResponseEntity<Iterable<Baker>> index() {
17
     public ResponseEntity<Iterable<Baker>> index() {
13
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
18
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
14
     }
19
     }
15
 
20
 
16
-    public ResponseEntity<Baker> show(Long id) {
21
+    @RequestMapping(value="/bakers/id", method= RequestMethod.GET)
22
+    public ResponseEntity<Baker> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
23
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
18
     }
24
     }
19
 
25
 
20
-    public ResponseEntity<Baker> create(Baker baker) {
26
+    @RequestMapping(value="/bakers", method= RequestMethod.POST)
27
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
21
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
28
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
22
     }
29
     }
23
 
30
 
24
-    public ResponseEntity<Baker> update(Long id, Baker baker) {
31
+    @RequestMapping(value="/bakers/id", method= RequestMethod.GET)
32
+    public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
25
         Baker foundBaker = bakerRepository.findOne(id);
33
         Baker foundBaker = bakerRepository.findOne(id);
26
 
34
 
27
         foundBaker.setName(baker.getName());
35
         foundBaker.setName(baker.getName());
30
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
38
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
31
     }
39
     }
32
 
40
 
33
-    public ResponseEntity<Boolean> destroy(Long id) {
41
+    @RequestMapping(value="/bakers/id", method= RequestMethod.DELETE)
42
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
34
         this.bakerRepository.delete(id);
43
         this.bakerRepository.delete(id);
35
         return new ResponseEntity<>(true, HttpStatus.OK);
44
         return new ResponseEntity<>(true, HttpStatus.OK);
36
     }
45
     }

+ 13
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java View File

2
 
2
 
3
 import com.zipcodewilmington.bakery.Models.Muffin;
3
 import com.zipcodewilmington.bakery.Models.Muffin;
4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
4
 import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
5
+import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.HttpStatus;
6
 import org.springframework.http.ResponseEntity;
7
 import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.*;
7
 
9
 
10
+@RestController
8
 public class MuffinController {
11
 public class MuffinController {
9
 
12
 
13
+    @Autowired
10
     private MuffinRepository muffinRepository;
14
     private MuffinRepository muffinRepository;
11
 
15
 
16
+    @RequestMapping(value="/muffins", method= RequestMethod.GET)
12
     public ResponseEntity<Iterable<Muffin>> index() {
17
     public ResponseEntity<Iterable<Muffin>> index() {
13
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
18
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14
     }
19
     }
15
 
20
 
16
-    public ResponseEntity<Muffin> show(Long id) {
21
+    @RequestMapping(value="/muffins/id", method= RequestMethod.GET)
22
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
23
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
18
     }
24
     }
19
 
25
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
26
+    @RequestMapping(value="/muffins", method= RequestMethod.POST)
27
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
21
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
28
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22
     }
29
     }
23
 
30
 
24
-    public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
31
+    @RequestMapping(value="/muffins/id", method= RequestMethod.GET)
32
+    public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
25
         Muffin foundMuffin = muffinRepository.findOne(id);
33
         Muffin foundMuffin = muffinRepository.findOne(id);
26
         foundMuffin.setFlavor(muffin.getFlavor());
34
         foundMuffin.setFlavor(muffin.getFlavor());
27
 
35
 
28
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
36
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29
     }
37
     }
30
 
38
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
39
+    @RequestMapping(value="/muffins/id", method= RequestMethod.DELETE)
40
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32
         this.muffinRepository.delete(id);
41
         this.muffinRepository.delete(id);
33
         return new ResponseEntity<>(true, HttpStatus.OK);
42
         return new ResponseEntity<>(true, HttpStatus.OK);
34
     }
43
     }

+ 7
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java View File

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
+import javax.persistence.Entity;
4
+import javax.persistence.GeneratedValue;
5
+import javax.persistence.Id;
6
+
7
+@Entity
3
 public class Baker {
8
 public class Baker {
9
+    @Id
10
+    @GeneratedValue
4
     private Long id;
11
     private Long id;
5
 
12
 
6
     private String name;
13
     private String name;

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

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