Skip to content

Commit 6f1d4bf

Browse files
committed
INDEX SHOW POST for dudes
1 parent 0ed4e9f commit 6f1d4bf

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

db/dark_heresy.mv.db

36 KB
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.bnta.dark_heresy_character_sheet.controllers;
2+
3+
public class WeaponController {
4+
}

0 commit comments

Comments
 (0)