fix(gacha): validate reward pool before charging currency (#175)

Filter out gacha entries with no items at the query level (EXISTS
subquery) and reorder Play methods to validate the pool before
calling transact(), so players are never charged for a misconfigured
gacha.
This commit is contained in:
Houmgaor
2026-03-10 11:28:11 +01:00
parent 915e9bc0b0
commit 2365b63e9c
4 changed files with 52 additions and 19 deletions

View File

@@ -29,10 +29,14 @@ func (r *GachaRepository) GetEntryForTransaction(gachaID uint32, rollID uint8) (
}
// GetRewardPool returns the entry_type=100 reward pool for a gacha, ordered by weight descending.
// Entries with no corresponding items in gacha_items are excluded.
func (r *GachaRepository) GetRewardPool(gachaID uint32) ([]GachaEntry, error) {
var entries []GachaEntry
rows, err := r.db.Queryx(
`SELECT id, weight, rarity FROM gacha_entries WHERE gacha_id = $1 AND entry_type = 100 ORDER BY weight DESC`,
`SELECT e.id, e.weight, e.rarity FROM gacha_entries e
WHERE e.gacha_id = $1 AND e.entry_type = 100
AND EXISTS (SELECT 1 FROM gacha_items gi WHERE gi.entry_id = e.id)
ORDER BY e.weight DESC`,
gachaID,
)
if err != nil {