Skip to content

Commit b2ffe61

Browse files
committed
added findWeaponByWeaponClassLike and findWeaponByCostGreaterThanEqual to controller
1 parent e90dc2f commit b2ffe61

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

db/dark_heresy.mv.db

8 KB
Binary file not shown.

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

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public class WeaponController {
2121

2222
//INDEX
2323
@GetMapping //localhost:8080/weapons
24-
public ResponseEntity<List<Weapon>> getAllWeapons(){
24+
public ResponseEntity<List<Weapon>> getAllWeaponsAndFilters(
25+
@RequestParam(name = "weaponClass",required = false) String weaponClass,
26+
@RequestParam(name = "cost",required = false) Integer cost){
27+
if(weaponClass != null && cost != null){
28+
return new ResponseEntity(weaponRepository.findWeaponByWeaponClassLike(weaponClass).addAll(weaponRepository.findWeaponByCostGreaterThanEqual(cost)),HttpStatus.OK);
29+
}
2530
return new ResponseEntity<>(weaponRepository.findAll(), HttpStatus.OK);
2631
}
2732

src/main/java/com/bnta/dark_heresy_character_sheet/repositories/WeaponRepository.java

+5
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@
33
import com.bnta.dark_heresy_character_sheet.models.Weapon;
44
import org.springframework.data.jpa.repository.JpaRepository;
55

6+
import java.util.List;
7+
68
public interface WeaponRepository extends JpaRepository<Weapon, Long> {
9+
10+
List<Weapon> findWeaponByWeaponClassLike(String weaponClass);
11+
List<Weapon> findWeaponByCostGreaterThanEqual(Integer cost);
712
}

0 commit comments

Comments
 (0)