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