|
@@ -3,44 +3,35 @@ 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.context.annotation.Bean;
|
7
|
6
|
import org.springframework.http.HttpStatus;
|
8
|
7
|
import org.springframework.http.ResponseEntity;
|
9
|
|
-import org.springframework.orm.jpa.JpaVendorAdapter;
|
10
|
|
-import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
11
|
|
-import org.springframework.stereotype.Controller;
|
12
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
13
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
14
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
15
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
16
|
|
-
|
17
|
|
-import javax.activation.DataSource;
|
18
|
|
-import javax.persistence.EntityManagerFactory;
|
19
|
|
-
|
20
|
|
-@Controller
|
|
8
|
+import org.springframework.web.bind.annotation.*;
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+@RestController
|
21
|
12
|
public class BakerController {
|
22
|
13
|
|
23
|
14
|
@Autowired
|
24
|
15
|
private BakerRepository bakerRepository;
|
25
|
16
|
|
26
|
17
|
|
27
|
|
- @GetMapping(path = "/baker")
|
|
18
|
+ @GetMapping("/baker")
|
28
|
19
|
public ResponseEntity<Iterable<Baker>> index() {
|
29
|
20
|
return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
|
30
|
21
|
}
|
31
|
22
|
|
32
|
|
- @GetMapping(path = "/baker/{id}")
|
33
|
|
- public ResponseEntity<Baker> show(Long id) {
|
|
23
|
+ @GetMapping("/baker/{id}")
|
|
24
|
+ public ResponseEntity<Baker> show(@PathVariable Long id) {
|
34
|
25
|
return new ResponseEntity<>(this.bakerRepository.findOne(id), HttpStatus.OK);
|
35
|
26
|
}
|
36
|
27
|
|
37
|
|
- @PostMapping(path = "/baker")
|
38
|
|
- public ResponseEntity<Baker> create(Baker baker) {
|
|
28
|
+ @PostMapping("/baker")
|
|
29
|
+ public ResponseEntity<Baker> create(@RequestBody Baker baker) {
|
39
|
30
|
return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
|
40
|
31
|
}
|
41
|
32
|
|
42
|
|
- @PutMapping(path = "/baker")
|
43
|
|
- public ResponseEntity<Baker> update(Long id, Baker baker) {
|
|
33
|
+ @PutMapping("/baker/{id}")
|
|
34
|
+ public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
|
44
|
35
|
Baker foundBaker = bakerRepository.findOne(id);
|
45
|
36
|
|
46
|
37
|
foundBaker.setName(baker.getName());
|
|
@@ -49,8 +40,8 @@ public class BakerController {
|
49
|
40
|
return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
|
50
|
41
|
}
|
51
|
42
|
|
52
|
|
- @DeleteMapping(path = "/baker")
|
53
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
|
43
|
+ @DeleteMapping("/baker/{id}")
|
|
44
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
54
|
45
|
this.bakerRepository.delete(id);
|
55
|
46
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
56
|
47
|
}
|