ThuyKhong 5 лет назад
Родитель
Сommit
d8d9e1ae81

+ 12
- 7
src/main/java/com/zipcodewilmington/bakery/Controllers/BakerController.java Просмотреть файл

3
 import com.zipcodewilmington.bakery.Models.Baker;
3
 import com.zipcodewilmington.bakery.Models.Baker;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
4
 import com.zipcodewilmington.bakery.Repositories.BakerRepository;
5
 import org.springframework.beans.factory.annotation.Autowired;
5
 import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpHeaders;
6
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.HttpStatus;
7
 import org.springframework.http.ResponseEntity;
8
 import org.springframework.http.ResponseEntity;
8
 import org.springframework.stereotype.Controller;
9
 import org.springframework.stereotype.Controller;
9
 import org.springframework.stereotype.Service;
10
 import org.springframework.stereotype.Service;
10
 import org.springframework.web.bind.annotation.*;
11
 import org.springframework.web.bind.annotation.*;
12
+import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
13
+
14
+import java.net.URI;
11
 
15
 
12
 @RestController
16
 @RestController
13
 public class BakerController {
17
 public class BakerController {
20
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
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
     public ResponseEntity<Baker> show(@PathVariable Long id) {
28
     public ResponseEntity<Baker> show(@PathVariable Long id) {
25
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
29
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
26
     }
30
     }
27
 
31
 
28
     @RequestMapping(value="/bakers", method= RequestMethod.POST)
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
         Baker foundBaker = bakerRepository.findById(id).get();
40
         Baker foundBaker = bakerRepository.findById(id).get();
36
 
41
 
37
         foundBaker.setName(baker.getName());
42
         foundBaker.setName(baker.getName());
40
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
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
         this.bakerRepository.delete(bakerRepository.findById(id).get());
50
         this.bakerRepository.delete(bakerRepository.findById(id).get());
46
         return new ResponseEntity<>(true, HttpStatus.OK);
51
         return new ResponseEntity<>(true, HttpStatus.OK);
47
     }
52
     }

+ 3
- 3
src/main/java/com/zipcodewilmington/bakery/Controllers/MuffinController.java Просмотреть файл

19
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
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
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
23
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
24
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
24
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
25
     }
25
     }
29
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
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
     public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
33
     public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
34
         Muffin foundMuffin = muffinRepository.findById(id).get();
34
         Muffin foundMuffin = muffinRepository.findById(id).get();
35
         foundMuffin.setFlavor(muffin.getFlavor());
35
         foundMuffin.setFlavor(muffin.getFlavor());
37
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
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
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
41
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
42
         this.muffinRepository.delete(muffinRepository.findById(id).get());
42
         this.muffinRepository.delete(muffinRepository.findById(id).get());
43
         return new ResponseEntity<>(true, HttpStatus.OK);
43
         return new ResponseEntity<>(true, HttpStatus.OK);