|
@@ -3,11 +3,15 @@ package com.zipcodewilmington.bakery.Controllers;
|
3
|
3
|
import com.zipcodewilmington.bakery.Models.Baker;
|
4
|
4
|
import com.zipcodewilmington.bakery.Repositories.BakerRepository;
|
5
|
5
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
6
|
+import org.springframework.http.HttpHeaders;
|
6
|
7
|
import org.springframework.http.HttpStatus;
|
7
|
8
|
import org.springframework.http.ResponseEntity;
|
8
|
9
|
import org.springframework.stereotype.Controller;
|
9
|
10
|
import org.springframework.stereotype.Service;
|
10
|
11
|
import org.springframework.web.bind.annotation.*;
|
|
12
|
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
|
13
|
+
|
|
14
|
+import java.net.URI;
|
11
|
15
|
|
12
|
16
|
@RestController
|
13
|
17
|
public class BakerController {
|
|
@@ -20,18 +24,19 @@ public class BakerController {
|
20
|
24
|
return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
|
21
|
25
|
}
|
22
|
26
|
|
23
|
|
- @RequestMapping(value = "/bakers/id", method = RequestMethod.GET)
|
|
27
|
+ @RequestMapping(value = "/bakers/{id}", method = RequestMethod.GET)
|
24
|
28
|
public ResponseEntity<Baker> show(@PathVariable Long id) {
|
25
|
29
|
return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
|
26
|
30
|
}
|
27
|
31
|
|
28
|
32
|
@RequestMapping(value="/bakers", method= RequestMethod.POST)
|
29
|
|
- public ResponseEntity<Baker> create(@PathVariable Baker baker) {
|
30
|
|
- return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
|
|
33
|
+ public ResponseEntity<Baker> create(@RequestBody Baker baker) {
|
|
34
|
+
|
|
35
|
+ return new ResponseEntity<>(bakerRepository.save(baker),HttpStatus.CREATED);
|
31
|
36
|
}
|
32
|
37
|
|
33
|
|
- @RequestMapping(value="/bakers/id", method= RequestMethod.PUT)
|
34
|
|
- public ResponseEntity<Baker> update(Long id, @PathVariable Baker baker) {
|
|
38
|
+ @RequestMapping(value="/bakers/{id}", method= RequestMethod.PUT)
|
|
39
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
|
35
|
40
|
Baker foundBaker = bakerRepository.findById(id).get();
|
36
|
41
|
|
37
|
42
|
foundBaker.setName(baker.getName());
|
|
@@ -40,8 +45,8 @@ public class BakerController {
|
40
|
45
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
41
|
46
|
}
|
42
|
47
|
|
43
|
|
- @RequestMapping(value="/bakers/id", method= RequestMethod.DELETE)
|
44
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
|
48
|
+ @RequestMapping(value="/bakers/{id}", method= RequestMethod.DELETE)
|
|
49
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
45
|
50
|
this.bakerRepository.delete(bakerRepository.findById(id).get());
|
46
|
51
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
47
|
52
|
}
|