Skip to content

Commit 95baace

Browse files
committed
Added Cascade DELETE
1 parent 6f1d4bf commit 95baace

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

db/dark_heresy.mv.db

-28 KB
Binary file not shown.

src/main/java/com/bnta/dark_heresy_character_sheet/controllers/DudeController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,21 @@ public ResponseEntity<List<Dude>> getAllDudes(){
2525

2626
//SHOW
2727
@GetMapping(value = "/{id}") //localhost:8080/dudes/1
28-
public ResponseEntity<Optional<Dude>> getPet(@PathVariable Long id){
28+
public ResponseEntity<Optional<Dude>> getDude(@PathVariable Long id){
2929
return new ResponseEntity<>(dudeRepository.findById(id), HttpStatus.OK);
3030
}
3131

3232
//POST
3333
@PostMapping //POST localhost:8080/dude
34-
public ResponseEntity<Dude> createPet(@RequestBody Dude newDude){
34+
public ResponseEntity<Dude> createDude(@RequestBody Dude newDude){
3535
dudeRepository.save(newDude);
3636
return new ResponseEntity<>(newDude, HttpStatus.CREATED);
3737
}
38+
39+
//DELETE
40+
@DeleteMapping(value = "/{id}")
41+
public ResponseEntity<Dude> deleteDude(@PathVariable Long id){
42+
dudeRepository.deleteById(id);
43+
return new ResponseEntity(id,HttpStatus.OK);
44+
}
3845
}

src/main/java/com/bnta/dark_heresy_character_sheet/models/Dude.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Dude {
1717
@Column
1818
private String name;
1919
@Column
20-
@OneToMany(mappedBy = "dude")
20+
@OneToMany(mappedBy = "dude", cascade = CascadeType.ALL)
2121
@JsonIgnoreProperties({"dude"})
2222
private List<Weapon> weapons;
2323

0 commit comments

Comments
 (0)