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