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