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