Simran Bhutani před 5 roky
rodič
revize
96e647ac73

binární
.DS_Store Zobrazit soubor


+ 15
- 5
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Zobrazit soubor

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

+ 13
- 4
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Zobrazit soubor

@@ -2,33 +2,42 @@ 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.*;
7 9
 
10
+@RestController
8 11
 public class MuffinController {
9 12
 
13
+    @Autowired
10 14
     private MuffinRepository muffinRepository;
11 15
 
16
+    @RequestMapping(value="/muffin",method = RequestMethod.GET)
12 17
     public ResponseEntity<Iterable<Muffin>> index() {
13 18
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
14 19
     }
15 20
 
16
-    public ResponseEntity<Muffin> show(Long id) {
21
+    @RequestMapping(value="/muffin/{id}",method = RequestMethod.GET)
22
+    public ResponseEntity<Muffin> show(@PathVariable Long id) {
17 23
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
18 24
     }
19 25
 
20
-    public ResponseEntity<Muffin> create(Muffin muffin) {
26
+    @RequestMapping(value="/muffin",method = RequestMethod.POST)
27
+    public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
21 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="/muffin/{id}",method = RequestMethod.PUT)
32
+    public ResponseEntity<Muffin> update(@PathVariable Long id,@RequestBody Muffin muffin) {
25 33
         Muffin foundMuffin = muffinRepository.findById(id).get();
26 34
         foundMuffin.setFlavor(muffin.getFlavor());
27 35
 
28 36
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
29 37
     }
30 38
 
31
-    public ResponseEntity<Boolean> destroy(Long id) {
39
+    @RequestMapping(value="/muffin/{id}",method = RequestMethod.DELETE)
40
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
32 41
         this.muffinRepository.deleteById(id);
33 42
         return new ResponseEntity<>(true, HttpStatus.OK);
34 43
     }

+ 13
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Zobrazit soubor

@@ -1,14 +1,27 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import javax.persistence.*;
4
+
5
+@Entity
3 6
 public class Baker {
7
+
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column(name = "BAKER_ID")
4 11
     private Long id;
5 12
 
13
+    @Column(name = "BAKER_NAME")
6 14
     private String name;
7 15
 
16
+    @Column(name = "BAKER_EMPLOYEEID")
8 17
     private String employeeId;
9 18
 
19
+    @Column(name = "BAKER_SPECIALTY")
10 20
     private String specialty;
11 21
 
22
+    public Baker() {
23
+    }
24
+
12 25
     public Baker(String name, String employeeId, String specialty) {
13 26
         this.name = name;
14 27
         this.employeeId = employeeId;

+ 11
- 0
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Zobrazit soubor

@@ -1,10 +1,21 @@
1 1
 package com.zipcodewilmington.bakery.Models;
2 2
 
3
+import javax.persistence.*;
4
+
5
+@Entity
3 6
 public class Muffin {
7
+
8
+    @Id
9
+    @GeneratedValue(strategy = GenerationType.AUTO)
10
+    @Column(name = "MUFFIN_ID")
4 11
     private Long id;
5 12
 
13
+    @Column(name = "MUFFIN_FLAVOR")
6 14
     private String flavor;
7 15
 
16
+    public Muffin() {
17
+    }
18
+
8 19
     public Muffin(String flavor) {
9 20
         this.flavor = flavor;
10 21
     }

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/BakerRepository.java Zobrazit soubor

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

+ 1
- 0
src/main/java/com/zipcodewilmington/bakery/Repositories/MuffinRepository.java Zobrazit soubor

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