|
@@ -2,26 +2,39 @@ 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
|
+import java.lang.reflect.Array;
|
|
11
|
+import java.util.*;
|
|
12
|
+import java.util.stream.Collectors;
|
|
13
|
+import java.util.stream.Stream;
|
|
14
|
+
|
|
15
|
+@RestController
|
8
|
16
|
public class BakerController {
|
9
|
17
|
|
|
18
|
+ @Autowired
|
10
|
19
|
private BakerRepository bakerRepository;
|
11
|
20
|
|
|
21
|
+ @GetMapping(path = "/bakers")
|
12
|
22
|
public ResponseEntity<Iterable<Baker>> index() {
|
13
|
23
|
return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
|
14
|
24
|
}
|
15
|
25
|
|
16
|
|
- public ResponseEntity<Baker> show(Long id) {
|
|
26
|
+ @GetMapping(path = "/bakers/{id}")
|
|
27
|
+ public ResponseEntity<Baker> show(@PathVariable Long id) {
|
17
|
28
|
return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
|
18
|
29
|
}
|
19
|
30
|
|
|
31
|
+ @PostMapping(path = "/bakers")
|
20
|
32
|
public ResponseEntity<Baker> create(Baker baker) {
|
21
|
33
|
return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
|
22
|
34
|
}
|
23
|
35
|
|
24
|
|
- public ResponseEntity<Baker> update(Long id, Baker baker) {
|
|
36
|
+ @PutMapping(path = "/bakers/{id}")
|
|
37
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, Baker baker) {
|
25
|
38
|
Baker foundBaker = bakerRepository.findOne(id);
|
26
|
39
|
|
27
|
40
|
foundBaker.setName(baker.getName());
|
|
@@ -30,8 +43,9 @@ public class BakerController {
|
30
|
43
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
31
|
44
|
}
|
32
|
45
|
|
33
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
|
46
|
+ @DeleteMapping(path = "/bakers/{id}")
|
|
47
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
34
|
48
|
this.bakerRepository.delete(id);
|
35
|
49
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
36
|
50
|
}
|
37
|
|
-}
|
|
51
|
+}
|