|
@@ -2,25 +2,34 @@ 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.web.bind.annotation.*;
|
7
|
9
|
|
|
10
|
+@RestController
|
8
|
11
|
public class MuffinController {
|
9
|
12
|
|
|
13
|
+ @Autowired
|
10
|
14
|
private MuffinRepository muffinRepository;
|
11
|
15
|
|
|
16
|
+
|
|
17
|
+ @GetMapping("/muffins")
|
12
|
18
|
public ResponseEntity<Iterable<Muffin>> index() {
|
13
|
19
|
return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
|
14
|
20
|
}
|
15
|
21
|
|
|
22
|
+ @GetMapping("/muffins")
|
16
|
23
|
public ResponseEntity<Muffin> show(Long id) {
|
17
|
24
|
return new ResponseEntity<>(this.muffinRepository.findOne(id), HttpStatus.OK);
|
18
|
25
|
}
|
19
|
26
|
|
|
27
|
+ @PostMapping("/muffins")
|
20
|
28
|
public ResponseEntity<Muffin> create(Muffin muffin) {
|
21
|
29
|
return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
|
22
|
30
|
}
|
23
|
31
|
|
|
32
|
+ @PutMapping("/muffins")
|
24
|
33
|
public ResponseEntity<Muffin> update(Long id, Muffin muffin) {
|
25
|
34
|
Muffin foundMuffin = muffinRepository.findOne(id);
|
26
|
35
|
foundMuffin.setFlavor(muffin.getFlavor());
|
|
@@ -28,6 +37,7 @@ public class MuffinController {
|
28
|
37
|
return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
|
29
|
38
|
}
|
30
|
39
|
|
|
40
|
+ @DeleteMapping("/muffins")
|
31
|
41
|
public ResponseEntity<Boolean> destroy(Long id) {
|
32
|
42
|
this.muffinRepository.delete(id);
|
33
|
43
|
return new ResponseEntity<>(true, HttpStatus.OK);
|