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