mpierse před 6 roky
rodič
revize
1d7499e7ee

+ 8
- 0
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Zobrazit soubor

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.GetMapping;
7
 import org.springframework.web.bind.annotation.RequestMapping;
9
 import org.springframework.web.bind.annotation.RequestMapping;
8
 import org.springframework.web.bind.annotation.RestController;
10
 import org.springframework.web.bind.annotation.RestController;
9
 
11
 
11
 @RequestMapping
13
 @RequestMapping
12
 public class BakerController {
14
 public class BakerController {
13
 
15
 
16
+    @Autowired
14
     private BakerRepository bakerRepository;
17
     private BakerRepository bakerRepository;
15
 
18
 
19
+    @GetMapping(value = "/baker")
16
     public ResponseEntity<Iterable<Baker>> index() {
20
     public ResponseEntity<Iterable<Baker>> index() {
17
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
21
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
18
     }
22
     }
19
 
23
 
24
+    @GetMapping(value = "/baker/{id}")
20
     public ResponseEntity<Baker> show(Long id) {
25
     public ResponseEntity<Baker> show(Long id) {
21
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
26
         return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
22
     }
27
     }
23
 
28
 
29
+    @GetMapping(value = "/baker")
24
     public ResponseEntity<Baker> create(Baker baker) {
30
     public ResponseEntity<Baker> create(Baker baker) {
25
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
31
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
26
     }
32
     }
27
 
33
 
34
+    @GetMapping(value = "/baker/{id}")
28
     public ResponseEntity<Baker> update(Long id, Baker baker) {
35
     public ResponseEntity<Baker> update(Long id, Baker baker) {
29
         Baker foundBaker = bakerRepository.findOne(id);
36
         Baker foundBaker = bakerRepository.findOne(id);
30
 
37
 
34
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
41
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
35
     }
42
     }
36
 
43
 
44
+    @GetMapping(value = "/baker/{id}")
37
     public ResponseEntity<Boolean> destroy(Long id) {
45
     public ResponseEntity<Boolean> destroy(Long id) {
38
         this.bakerRepository.delete(id);
46
         this.bakerRepository.delete(id);
39
         return new ResponseEntity<>(true, HttpStatus.OK);
47
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 5
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Zobrazit soubor

17
     @Autowired
17
     @Autowired
18
     private MuffinRepository muffinRepository;
18
     private MuffinRepository muffinRepository;
19
 
19
 
20
-    @GetMapping(value="/polls/votes")
20
+    @GetMapping(value="/muffin")
21
     public ResponseEntity<Iterable<Muffin>> index() {
21
     public ResponseEntity<Iterable<Muffin>> index() {
22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
23
     }
23
     }
24
 
24
 
25
-
25
+    @GetMapping(value="/muffin/{id}")
26
     public ResponseEntity<Muffin> show(Long id) {
26
     public ResponseEntity<Muffin> show(Long id) {
27
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
27
         return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
28
     }
28
     }
29
-
29
+    @GetMapping(value = "/muffin")
30
     public ResponseEntity<Muffin> create(Muffin muffin) {
30
     public ResponseEntity<Muffin> create(Muffin muffin) {
31
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
31
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
32
     }
32
     }
33
 
33
 
34
+    @GetMapping(value ="/muffin/{id}")
34
     public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
35
     public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
35
         Muffin foundMuffin = muffinRepository.findOne(id);
36
         Muffin foundMuffin = muffinRepository.findOne(id);
36
         foundMuffin.setFlavor(muffin.getFlavor());
37
         foundMuffin.setFlavor(muffin.getFlavor());
38
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
39
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
39
     }
40
     }
40
 
41
 
42
+    @GetMapping(value = "/muffin/{id}")
41
     public ResponseEntity<Boolean> destroy(Long id) {
43
     public ResponseEntity<Boolean> destroy(Long id) {
42
         this.muffinRepository.delete(id);
44
         this.muffinRepository.delete(id);
43
         return new ResponseEntity<>(true, HttpStatus.OK);
45
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 8
- 3
src/main/java/com/zipcodewilmington/bakery/Models/Baker.java Zobrazit soubor

1
 package com.zipcodewilmington.bakery.Models;
1
 package com.zipcodewilmington.bakery.Models;
2
 
2
 
3
+import org.springframework.web.bind.annotation.PathVariable;
4
+
3
 import javax.persistence.Column;
5
 import javax.persistence.Column;
4
 import javax.persistence.Entity;
6
 import javax.persistence.Entity;
5
 import javax.persistence.GeneratedValue;
7
 import javax.persistence.GeneratedValue;
9
 public class Baker {
11
 public class Baker {
10
     @Id
12
     @Id
11
     @GeneratedValue
13
     @GeneratedValue
14
+    @Column(name = "id")
12
     private Long id;
15
     private Long id;
13
 
16
 
14
-    @Column
17
+    @Column(name = "bakerName")
15
     private String name;
18
     private String name;
16
-    @Column
19
+
20
+    @Column(name = "employeeId")
17
     private String employeeId;
21
     private String employeeId;
18
-    @Column
22
+
23
+    @Column(name = "specialty")
19
     private String specialty;
24
     private String specialty;
20
 
25
 
21
     public Baker(String name, String employeeId, String specialty) {
26
     public Baker(String name, String employeeId, String specialty) {

+ 5
- 1
src/main/java/com/zipcodewilmington/bakery/Models/Muffin.java Zobrazit soubor

2
 
2
 
3
 import javax.persistence.Column;
3
 import javax.persistence.Column;
4
 import javax.persistence.Entity;
4
 import javax.persistence.Entity;
5
+import javax.persistence.GeneratedValue;
5
 import javax.persistence.Id;
6
 import javax.persistence.Id;
6
 
7
 
7
 @Entity
8
 @Entity
8
 public class Muffin {
9
 public class Muffin {
9
 
10
 
10
     @Id
11
     @Id
12
+    @GeneratedValue
13
+    @Column(name = "id")
11
     private Long id;
14
     private Long id;
12
-    @Column
15
+
16
+    @Column(name = "flavor")
13
     private String flavor;
17
     private String flavor;
14
 
18
 
15
     public Muffin(String flavor) {
19
     public Muffin(String flavor) {