|
@@ -2,25 +2,44 @@ 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
|
+
|
|
11
|
+@RestController
|
8
|
12
|
public class BakerController {
|
|
13
|
+
|
|
14
|
+
|
9
|
15
|
private BakerRepository bakerRepository;
|
10
|
16
|
|
|
17
|
+ public BakerController() {
|
|
18
|
+ }
|
|
19
|
+
|
|
20
|
+ @Autowired
|
|
21
|
+ public BakerController(BakerRepository bakerRepository) {
|
|
22
|
+ this.bakerRepository = bakerRepository;
|
|
23
|
+ }
|
|
24
|
+
|
|
25
|
+ @GetMapping("/Baker")
|
11
|
26
|
public ResponseEntity<Iterable<Baker>> index() {
|
12
|
27
|
return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
|
|
28
|
+ //find here means we are retriving the data
|
13
|
29
|
}
|
14
|
30
|
|
15
|
|
- public ResponseEntity<Baker> show(Long id) {
|
|
31
|
+ @GetMapping("/Baker/{id}")
|
|
32
|
+ public ResponseEntity<Baker> show(@PathVariable Long id) {
|
16
|
33
|
return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
|
17
|
34
|
}
|
18
|
35
|
|
19
|
|
- public ResponseEntity<Baker> create(Baker baker) {
|
|
36
|
+ @PostMapping("/Baker")
|
|
37
|
+ public ResponseEntity<Baker> create(@RequestBody Baker baker) {
|
20
|
38
|
return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
|
21
|
39
|
}
|
22
|
40
|
|
23
|
|
- public ResponseEntity<Baker> update(Long id, Baker baker) {
|
|
41
|
+ @PutMapping("/Backer/{id}")
|
|
42
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
|
24
|
43
|
Baker foundBaker = bakerRepository.findById(id).get();
|
25
|
44
|
|
26
|
45
|
foundBaker.setName(baker.getName());
|
|
@@ -29,8 +48,9 @@ public class BakerController {
|
29
|
48
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
30
|
49
|
}
|
31
|
50
|
|
32
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
33
|
|
- this.bakerRepository.findById(id).get();
|
|
51
|
+ @DeleteMapping("/Backer/{id}")
|
|
52
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
|
53
|
+ this.bakerRepository.delete(this.bakerRepository.findById(id).get());
|
34
|
54
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
35
|
55
|
}
|
36
|
56
|
}
|