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