Browse Source

Annotations done

Jose Bedolla 5 years ago
parent
commit
d8a3751da2

BIN
.DS_Store View File


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

@@ -1,6 +1,7 @@
1 1
 package com.zipcodewilmington.bakery;
2 2
 
3 3
 import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4 5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5 6
 
6 7
 @SpringBootApplication

+ 17
- 2
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java View File

@@ -2,24 +2,39 @@ 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.stereotype.Controller;
9
+import org.springframework.stereotype.Repository;
10
+import org.springframework.web.bind.annotation.PostMapping;
11
+import org.springframework.web.bind.annotation.RequestMapping;
12
+import org.springframework.web.bind.annotation.RequestMethod;
13
+import org.springframework.web.bind.annotation.RestController;
7 14
 
15
+import javax.persistence.Entity;
16
+
17
+@RestController
18
+//@RequestMapping("/bake")
8 19
 public class BakerController {
20
+    @Autowired
9 21
     private BakerRepository bakerRepository;
10 22
 
23
+    @RequestMapping("/")
11 24
     public ResponseEntity<Iterable<Baker>> index() {
12 25
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
13 26
     }
14
-
27
+    //@PostMapping("/request")
28
+    @RequestMapping
15 29
     public ResponseEntity<Baker> show(Long id) {
16 30
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
17 31
     }
18
-
32
+    @RequestMapping
19 33
     public ResponseEntity<Baker> create(Baker baker) {
20 34
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
21 35
     }
22 36
 
37
+    @RequestMapping//(method = RequestMethod.GET)
23 38
     public ResponseEntity<Baker> update(Long id, Baker baker) {
24 39
         Baker foundBaker = bakerRepository.findById(id).get();
25 40
 

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

@@ -2,25 +2,33 @@ 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.PostMapping;
9
+import org.springframework.web.bind.annotation.RequestBody;
10
+import org.springframework.web.bind.annotation.RequestMapping;
11
+import org.springframework.web.bind.annotation.RestController;
7 12
 
13
+@RestController
14
+//@RequestMapping("MUFFIN")
8 15
 public class MuffinController {
9
-
16
+    @Autowired
10 17
     private MuffinRepository muffinRepository;
11 18
 
19
+    @RequestMapping
12 20
     public ResponseEntity<Iterable<Muffin>> index() {
13 21
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 22
     }
15
-
23
+    @RequestMapping
16 24
     public ResponseEntity<Muffin> show(Long id) {
17 25
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
18 26
     }
19
-
27
+    @RequestMapping
20 28
     public ResponseEntity<Muffin> create(Muffin muffin) {
21 29
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
22 30
     }
23
-
31
+    @RequestMapping
24 32
     public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
25 33
         Muffin foundMuffin = muffinRepository.findById(id).get();
26 34
         foundMuffin.setFlavor(muffin.getFlavor());

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

@@ -1,6 +1,13 @@
1 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 8
 public class Baker {
9
+    @Id
10
+    @GeneratedValue
4 11
     private Long id;
5 12
 
6 13
     private String name;

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

@@ -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.Id;
6
+import javax.persistence.Table;
7
+
8
+@Entity
9
+//@Table(name = "muffin")
3 10
 public class Muffin {
11
+    @Id
12
+    @GeneratedValue
4 13
     private Long id;
5 14
 
6 15
     private String flavor;

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java View File

@@ -3,6 +3,8 @@ package com.zipcodewilmington.bakery.Repositories;
3 3
 import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6
+import org.springframework.stereotype.Service;
6 7
 
8
+@Repository
7 9
 public interface BakerRepository extends CrudRepository<Baker, Long> {
8 10
 }

+ 2
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java View File

@@ -3,6 +3,8 @@ package com.zipcodewilmington.bakery.Repositories;
3 3
 import com.zipcodewilmington.bakery.Models.Muffin;
4 4
 import org.springframework.data.repository.CrudRepository;
5 5
 import org.springframework.stereotype.Repository;
6
+import org.springframework.stereotype.Service;
6 7
 
8
+@Repository
7 9
 public interface MuffinRepository extends CrudRepository<Muffin, Long> {
8 10
 }