Skip to content

Commit e90dc2f

Browse files
committed
WeaponController INDEX SHOW POST DELETE
1 parent 95baace commit e90dc2f

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

db/dark_heresy.mv.db

-4 KB
Binary file not shown.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public ResponseEntity<Optional<Dude>> getDude(@PathVariable Long id){
3030
}
3131

3232
//POST
33-
@PostMapping //POST localhost:8080/dude
33+
@PostMapping // localhost:8080/dudes
3434
public ResponseEntity<Dude> createDude(@RequestBody Dude newDude){
3535
dudeRepository.save(newDude);
3636
return new ResponseEntity<>(newDude, HttpStatus.CREATED);
3737
}
3838

3939
//DELETE
40-
@DeleteMapping(value = "/{id}")
40+
@DeleteMapping(value = "/{id}") //localhost:8080/dudes/1
4141
public ResponseEntity<Dude> deleteDude(@PathVariable Long id){
4242
dudeRepository.deleteById(id);
4343
return new ResponseEntity(id,HttpStatus.OK);
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
11
package com.bnta.dark_heresy_character_sheet.controllers;
22

3+
import com.bnta.dark_heresy_character_sheet.models.Dude;
4+
import com.bnta.dark_heresy_character_sheet.models.Weapon;
5+
import com.bnta.dark_heresy_character_sheet.repositories.DudeRepository;
6+
import com.bnta.dark_heresy_character_sheet.repositories.WeaponRepository;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.http.HttpStatus;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.web.bind.annotation.*;
11+
12+
import java.util.List;
13+
import java.util.Optional;
14+
15+
@RestController
16+
@RequestMapping("weapons")
317
public class WeaponController {
18+
19+
@Autowired
20+
WeaponRepository weaponRepository;
21+
22+
//INDEX
23+
@GetMapping //localhost:8080/weapons
24+
public ResponseEntity<List<Weapon>> getAllWeapons(){
25+
return new ResponseEntity<>(weaponRepository.findAll(), HttpStatus.OK);
26+
}
27+
28+
//SHOW
29+
@GetMapping(value = "/{id}") //localhost:8080/weapons/1
30+
public ResponseEntity<Optional<Weapon>> getWeapon(@PathVariable Long id){
31+
return new ResponseEntity<>(weaponRepository.findById(id), HttpStatus.OK);
32+
}
33+
34+
//POST
35+
@PostMapping //POST localhost:8080/weapons
36+
public ResponseEntity<Weapon> createWeapon(@RequestBody Weapon newWeapon){
37+
weaponRepository.save(newWeapon);
38+
return new ResponseEntity<>(newWeapon, HttpStatus.CREATED);
39+
}
40+
41+
//DELETE
42+
@DeleteMapping(value = "/{id}") //localhost:8080/weapons/1
43+
public ResponseEntity<Weapon> deleteWeapon(@PathVariable Long id){
44+
weaponRepository.deleteById(id);
45+
return new ResponseEntity(id,HttpStatus.OK);
46+
}
447
}

0 commit comments

Comments
 (0)