Pārlūkot izejas kodu

updated, fully functional

ThuyKhong 5 gadus atpakaļ
vecāks
revīzija
d8d9e1ae81

+ 12
- 7
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Parādīt failu

@@ -3,11 +3,15 @@ package com.zipcodewilmington.bakery.Controllers;
3 3
 import com.zipcodewilmington.bakery.Models.Baker;
4 4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5 5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpHeaders;
6 7
 import org.springframework.http.HttpStatus;
7 8
 import org.springframework.http.ResponseEntity;
8 9
 import org.springframework.stereotype.Controller;
9 10
 import org.springframework.stereotype.Service;
10 11
 import org.springframework.web.bind.annotation.*;
12
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
13
+
14
+import java.net.URI;
11 15
 
12 16
 @RestController
13 17
 public class BakerController {
@@ -20,18 +24,19 @@ public class BakerController {
20 24
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
21 25
     }
22 26
 
23
-    @RequestMapping(value = "/bakers/id", method = RequestMethod.GET)
27
+    @RequestMapping(value = "/bakers/{id}", method = RequestMethod.GET)
24 28
     public ResponseEntity<Baker> show(@PathVariable Long id) {
25 29
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
26 30
     }
27 31
 
28 32
     @RequestMapping(value="/bakers", method= RequestMethod.POST)
29
-    public ResponseEntity<Baker> create(@PathVariable Baker baker) {
30
-        return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
33
+    public ResponseEntity<Baker> create(@RequestBody Baker baker) {
34
+
35
+        return new ResponseEntity<>(bakerRepository.save(baker),HttpStatus.CREATED);
31 36
     }
32 37
 
33
-    @RequestMapping(value="/bakers/id", method= RequestMethod.PUT)
34
-    public ResponseEntity<Baker> update(Long id, @PathVariable Baker baker) {
38
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.PUT)
39
+    public ResponseEntity<Baker> update(@PathVariable Long id,  @RequestBody Baker baker) {
35 40
         Baker foundBaker = bakerRepository.findById(id).get();
36 41
 
37 42
         foundBaker.setName(baker.getName());
@@ -40,8 +45,8 @@ public class BakerController {
40 45
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
41 46
     }
42 47
 
43
-    @RequestMapping(value="/bakers/id", method= RequestMethod.DELETE)
44
-    public ResponseEntity<Boolean> destroy(Long id) {
48
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.DELETE)
49
+    public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
45 50
         this.bakerRepository.delete(bakerRepository.findById(id).get());
46 51
         return new ResponseEntity<>(true, HttpStatus.OK);
47 52
     }

+ 3
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Parādīt failu

@@ -19,7 +19,7 @@ public class MuffinController {
19 19
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
20 20
     }
21 21
 
22
-    @RequestMapping(value = "/muffins/id", method=RequestMethod.GET)
22
+    @RequestMapping(value = "/muffins/{id}", method=RequestMethod.GET)
23 23
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
24 24
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
25 25
     }
@@ -29,7 +29,7 @@ public class MuffinController {
29 29
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
30 30
     }
31 31
 
32
-    @RequestMapping(value = "/muffins/id", method=RequestMethod.PUT)
32
+    @RequestMapping(value = "/muffins/{id}", method=RequestMethod.PUT)
33 33
     public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
34 34
         Muffin foundMuffin = muffinRepository.findById(id).get();
35 35
         foundMuffin.setFlavor(muffin.getFlavor());
@@ -37,7 +37,7 @@ public class MuffinController {
37 37
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
38 38
     }
39 39
 
40
-    @RequestMapping(value = "/muffins/id", method = RequestMethod.DELETE)
40
+    @RequestMapping(value = "/muffins/{id}", method = RequestMethod.DELETE)
41 41
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
42 42
         this.muffinRepository.delete(muffinRepository.findById(id).get());
43 43
         return new ResponseEntity<>(true, HttpStatus.OK);