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
 package com.zipcodewilmington.bakery;
1
 package com.zipcodewilmington.bakery;
2
 
2
 
3
 import org.springframework.boot.SpringApplication;
3
 import org.springframework.boot.SpringApplication;
4
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
4
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
5
 
6
 
6
 @SpringBootApplication
7
 @SpringBootApplication

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

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

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

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

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

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

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

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