|
@@ -5,10 +5,7 @@ import com.zipcodewilmington.bakery.Repositories.BakerRepository;
|
5
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
6
|
6
|
import org.springframework.http.HttpStatus;
|
7
|
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;
|
|
8
|
+import org.springframework.web.bind.annotation.*;
|
12
|
9
|
|
13
|
10
|
@RestController
|
14
|
11
|
public class BakerController {
|
|
@@ -20,30 +17,30 @@ public class BakerController {
|
20
|
17
|
this.bakerRepository = bakerRepository;
|
21
|
18
|
}
|
22
|
19
|
|
23
|
|
- @RequestMapping(value="/bakers", method= RequestMethod.GET)
|
|
20
|
+ @GetMapping(value="/bakers")
|
24
|
21
|
public ResponseEntity<Iterable<Baker>> index() {
|
25
|
22
|
return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
|
26
|
23
|
}
|
27
|
24
|
|
28
|
|
- @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.GET)
|
|
25
|
+ @GetMapping(value="/bakers/{id}")
|
29
|
26
|
public ResponseEntity<Baker> show(@PathVariable Long id) {
|
30
|
27
|
return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
|
31
|
28
|
}
|
32
|
29
|
|
33
|
|
- @RequestMapping(value="/bakers", method= RequestMethod.POST)
|
34
|
|
- public ResponseEntity<Baker> create(Baker baker) {
|
|
30
|
+ @PostMapping(value="/bakers")
|
|
31
|
+ public ResponseEntity<Baker> create(@RequestBody Baker baker) {
|
35
|
32
|
return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
|
36
|
33
|
}
|
37
|
34
|
|
38
|
|
- @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.PUT)
|
39
|
|
- public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
|
|
35
|
+ @PutMapping(value="/bakers/{id}")
|
|
36
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
|
40
|
37
|
Baker foundBaker = bakerRepository.findOne(id);
|
41
|
38
|
foundBaker.setName(baker.getName());
|
42
|
39
|
foundBaker.setSpecialty(baker.getSpecialty());
|
43
|
40
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
44
|
41
|
}
|
45
|
42
|
|
46
|
|
- @RequestMapping(value="/bakers/{BAKER_ID}", method=RequestMethod.DELETE)
|
|
43
|
+ @DeleteMapping(value="/bakers/{id}")
|
47
|
44
|
public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
48
|
45
|
this.bakerRepository.delete(id);
|
49
|
46
|
return new ResponseEntity<>(true, HttpStatus.OK);
|