|
|
@@ -2,33 +2,47 @@ package com.zipcodewilmington.bakery.Controllers;
|
|
2
|
2
|
|
|
3
|
3
|
import com.zipcodewilmington.bakery.Models.Muffin;
|
|
4
|
4
|
import com.zipcodewilmington.bakery.Repositories.MuffinRepository;
|
|
|
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.web.bind.annotation.*;
|
|
7
|
10
|
|
|
|
11
|
+import javax.persistence.EntityManager;
|
|
|
12
|
+import javax.persistence.EntityManagerFactory;
|
|
|
13
|
+import javax.persistence.Persistence;
|
|
|
14
|
+
|
|
|
15
|
+@RestController
|
|
8
|
16
|
public class MuffinController {
|
|
9
|
17
|
|
|
|
18
|
+ @Autowired
|
|
10
|
19
|
private MuffinRepository muffinRepository;
|
|
11
|
20
|
|
|
|
21
|
+ @GetMapping("/muffin")
|
|
12
|
22
|
public ResponseEntity<Iterable<Muffin>> index() {
|
|
13
|
23
|
return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
|
|
14
|
24
|
}
|
|
15
|
25
|
|
|
16
|
|
- public ResponseEntity<Muffin> show(Long id) {
|
|
|
26
|
+ @GetMapping("/muffin/{id}")
|
|
|
27
|
+ public ResponseEntity<Muffin> show(@PathVariable Long id) {
|
|
17
|
28
|
return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
|
|
18
|
29
|
}
|
|
19
|
30
|
|
|
20
|
|
- public ResponseEntity<Muffin> create(Muffin muffin) {
|
|
|
31
|
+ @PostMapping("/muffin")
|
|
|
32
|
+ public ResponseEntity<Muffin> create(@RequestBody Muffin muffin) {
|
|
21
|
33
|
return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
|
|
22
|
34
|
}
|
|
23
|
35
|
|
|
24
|
|
- public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
|
|
|
36
|
+ @PutMapping("/muffin/{id}")
|
|
|
37
|
+ public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
|
|
25
|
38
|
Muffin foundMuffin = muffinRepository.findOne(id);
|
|
26
|
39
|
foundMuffin.setFlavor(muffin.getFlavor());
|
|
27
|
40
|
|
|
28
|
41
|
return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
|
|
29
|
42
|
}
|
|
30
|
43
|
|
|
31
|
|
- public ResponseEntity<Boolean> destroy(Long id) {
|
|
|
44
|
+ @DeleteMapping("/muffin/{id}")
|
|
|
45
|
+ public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
|
|
32
|
46
|
this.muffinRepository.delete(id);
|
|
33
|
47
|
return new ResponseEntity<>(true, HttpStatus.OK);
|
|
34
|
48
|
}
|