|
@@ -5,9 +5,8 @@ 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.GetMapping;
|
9
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
10
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
8
|
+import org.springframework.stereotype.Controller;
|
|
9
|
+import org.springframework.web.bind.annotation.*;
|
11
|
10
|
|
12
|
11
|
@RestController
|
13
|
12
|
public class BakerController {
|
|
@@ -17,18 +16,25 @@ public class BakerController {
|
17
|
16
|
|
18
|
17
|
@GetMapping("/bakers")
|
19
|
18
|
public ResponseEntity<Iterable<Baker>> index() {
|
|
19
|
+
|
20
|
20
|
return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
|
21
|
21
|
}
|
22
|
|
- @GetMapping("/bakers")
|
23
|
|
- public ResponseEntity<Baker> show(Long id) {
|
|
22
|
+
|
|
23
|
+ @GetMapping("/bakers/{id}")
|
|
24
|
+ public ResponseEntity<Baker> show(@PathVariable Long id) {
|
|
25
|
+
|
24
|
26
|
return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
|
25
|
27
|
}
|
26
|
|
- @GetMapping("/bakers")
|
27
|
|
- public ResponseEntity<Baker> create(Baker baker) {
|
|
28
|
+
|
|
29
|
+ @PostMapping("/bakers")
|
|
30
|
+ public ResponseEntity<Baker> create(@PathVariable Baker baker) {
|
|
31
|
+
|
28
|
32
|
return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
|
29
|
33
|
}
|
30
|
|
- @GetMapping("/bakers")
|
31
|
|
- public ResponseEntity<Baker> update(Long id, Baker baker) {
|
|
34
|
+
|
|
35
|
+ @PutMapping("/bakers/{id}")
|
|
36
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
|
|
37
|
+
|
32
|
38
|
Baker foundBaker = bakerRepository.findOne(id);
|
33
|
39
|
|
34
|
40
|
foundBaker.setName(baker.getName());
|
|
@@ -36,9 +42,12 @@ public class BakerController {
|
36
|
42
|
|
37
|
43
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
38
|
44
|
}
|
39
|
|
- @GetMapping("/bakers")
|
40
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
|
45
|
+
|
|
46
|
+ @DeleteMapping("/bakers/{id}")
|
|
47
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
|
48
|
+
|
41
|
49
|
this.bakerRepository.delete(id);
|
|
50
|
+
|
42
|
51
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
43
|
52
|
}
|
44
|
53
|
}
|