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