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