ソースを参照

fixed path variables

Lauren Green 5 年 前
コミット
44bf8993e9

+ 3
- 3
src/main/java/com/example/demo/Controllers/BakerController.java ファイルの表示

22
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
22
         return new ResponseEntity<>(this.bakerRepository.findAll(), HttpStatus.OK);
23
     }
23
     }
24
 
24
 
25
-    @RequestMapping(value="/bakers/id", method= RequestMethod.GET)
25
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.GET)
26
     public ResponseEntity<Baker> show(@PathVariable Long id) {
26
     public ResponseEntity<Baker> show(@PathVariable Long id) {
27
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
27
         return new ResponseEntity<>(this.bakerRepository.findById(id).get(), HttpStatus.OK);
28
     }
28
     }
32
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
32
         return new ResponseEntity<>(this.bakerRepository.save(baker), HttpStatus.CREATED);
33
     }
33
     }
34
 
34
 
35
-    @RequestMapping(value="/bakers/id", method= RequestMethod.PUT)
35
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.PUT)
36
     public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
36
     public ResponseEntity<Baker> update(@PathVariable Long id, @RequestBody Baker baker) {
37
         Baker foundBaker = bakerRepository.findById(id).get();
37
         Baker foundBaker = bakerRepository.findById(id).get();
38
 
38
 
42
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
42
         return new ResponseEntity<>(this.bakerRepository.save(foundBaker), HttpStatus.OK);
43
     }
43
     }
44
 
44
 
45
-    @RequestMapping(value="/bakers/id", method= RequestMethod.DELETE)
45
+    @RequestMapping(value="/bakers/{id}", method= RequestMethod.DELETE)
46
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
46
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
47
         this.bakerRepository.deleteById(id);
47
         this.bakerRepository.deleteById(id);
48
         return new ResponseEntity<>(true, HttpStatus.OK);
48
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 3
- 3
src/main/java/com/example/demo/Controllers/MuffinController.java ファイルの表示

22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
22
         return new ResponseEntity<>(this.muffinRepository.findAll(), HttpStatus.OK);
23
     }
23
     }
24
 
24
 
25
-    @RequestMapping(value="/muffins/id", method= RequestMethod.GET)
25
+    @RequestMapping(value="/muffins/{id}", method= RequestMethod.GET)
26
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
26
     public ResponseEntity<Muffin> show(@PathVariable Long id) {
27
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
27
         return new ResponseEntity<>(this.muffinRepository.findById(id).get(), HttpStatus.OK);
28
     }
28
     }
32
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
32
         return new ResponseEntity<>(this.muffinRepository.save(muffin), HttpStatus.CREATED);
33
     }
33
     }
34
 
34
 
35
-    @RequestMapping(value="/muffins/id", method= RequestMethod.PUT)
35
+    @RequestMapping(value="/muffins/{id}", method= RequestMethod.PUT)
36
     public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
36
     public ResponseEntity<Muffin> update(@PathVariable Long id, @RequestBody Muffin muffin) {
37
         Muffin foundMuffin = muffinRepository.findById(id).get();
37
         Muffin foundMuffin = muffinRepository.findById(id).get();
38
         foundMuffin.setFlavor(muffin.getFlavor());
38
         foundMuffin.setFlavor(muffin.getFlavor());
40
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
40
         return new ResponseEntity<>(this.muffinRepository.save(foundMuffin), HttpStatus.OK);
41
     }
41
     }
42
 
42
 
43
-    @RequestMapping(value="/muffins/id", method= RequestMethod.DELETE)
43
+    @RequestMapping(value="/muffins/{id}", method= RequestMethod.DELETE)
44
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
44
     public ResponseEntity<Boolean> destroy(@PathVariable Long id) {
45
         this.muffinRepository.deleteById(id);
45
         this.muffinRepository.deleteById(id);
46
         return new ResponseEntity<>(true, HttpStatus.OK);
46
         return new ResponseEntity<>(true, HttpStatus.OK);

+ 1
- 0
src/test/java/com/example/demo/BakeryApplicationTests.java ファイルの表示

26
         Assert.assertNotNull(muffinController);
26
         Assert.assertNotNull(muffinController);
27
     }
27
     }
28
 
28
 
29
+
29
 }
30
 }