|
@@ -2,35 +2,49 @@ 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/{BAKER_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/{BAKER_ID}", method=RequestMethod.PUT)
|
|
39
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
|
25
|
40
|
Baker foundBaker = bakerRepository.findOne(id);
|
26
|
|
-
|
27
|
41
|
foundBaker.setName(baker.getName());
|
28
|
42
|
foundBaker.setSpecialty(baker.getSpecialty());
|
29
|
|
-
|
30
|
43
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
31
|
44
|
}
|
32
|
45
|
|
33
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
|
46
|
+ @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.DELETE)
|
|
47
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
34
|
48
|
this.bakerRepository.delete(id);
|
35
|
49
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
36
|
50
|
}
|