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