File tree Expand file tree Collapse file tree 3 files changed +42
-0
lines changed
src/main/java/com/bnta/dark_heresy_character_sheet/controllers Expand file tree Collapse file tree 3 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .bnta .dark_heresy_character_sheet .controllers ;
2
+
3
+ import com .bnta .dark_heresy_character_sheet .models .Dude ;
4
+ import com .bnta .dark_heresy_character_sheet .repositories .DudeRepository ;
5
+ import org .springframework .beans .factory .annotation .Autowired ;
6
+ import org .springframework .http .HttpStatus ;
7
+ import org .springframework .http .ResponseEntity ;
8
+ import org .springframework .web .bind .annotation .*;
9
+
10
+ import java .util .List ;
11
+ import java .util .Optional ;
12
+
13
+ @ RestController
14
+ @ RequestMapping ("dudes" )
15
+ public class DudeController {
16
+
17
+ @ Autowired
18
+ DudeRepository dudeRepository ;
19
+
20
+ //INDEX
21
+ @ GetMapping //localhost:8080/dudes
22
+ public ResponseEntity <List <Dude >> getAllDudes (){
23
+ return new ResponseEntity <>(dudeRepository .findAll (), HttpStatus .OK );
24
+ }
25
+
26
+ //SHOW
27
+ @ GetMapping (value = "/{id}" ) //localhost:8080/dudes/1
28
+ public ResponseEntity <Optional <Dude >> getPet (@ PathVariable Long id ){
29
+ return new ResponseEntity <>(dudeRepository .findById (id ), HttpStatus .OK );
30
+ }
31
+
32
+ //POST
33
+ @ PostMapping //POST localhost:8080/dude
34
+ public ResponseEntity <Dude > createPet (@ RequestBody Dude newDude ){
35
+ dudeRepository .save (newDude );
36
+ return new ResponseEntity <>(newDude , HttpStatus .CREATED );
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ package com .bnta .dark_heresy_character_sheet .controllers ;
2
+
3
+ public class WeaponController {
4
+ }
You can’t perform that action at this time.
0 commit comments