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