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