Soujanya Buragapu 5 jaren geleden
bovenliggende
commit
91cd3add9e

BIN
.DS_Store Bestand weergeven


+ 23
- 9
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Bestand weergeven

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

+ 19
- 11
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Bestand weergeven

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

+ 15
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Bestand weergeven

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

+ 14
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Bestand weergeven

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