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