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