refactor(spotcard): centralize spot-point spend via CurrencySpendService
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -30,12 +30,14 @@ public class SpotCardExchangeController : SVSimController
|
|||||||
private readonly SVSimDbContext _db;
|
private readonly SVSimDbContext _db;
|
||||||
private readonly RewardGrantService _rewards;
|
private readonly RewardGrantService _rewards;
|
||||||
private readonly TimeProvider _time;
|
private readonly TimeProvider _time;
|
||||||
|
private readonly ICurrencySpendService _spend;
|
||||||
|
|
||||||
public SpotCardExchangeController(SVSimDbContext db, RewardGrantService rewards, TimeProvider time)
|
public SpotCardExchangeController(SVSimDbContext db, RewardGrantService rewards, TimeProvider time, ICurrencySpendService spend)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_rewards = rewards;
|
_rewards = rewards;
|
||||||
_time = time;
|
_time = time;
|
||||||
|
_spend = spend;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("top")]
|
[HttpPost("top")]
|
||||||
@@ -131,14 +133,14 @@ public class SpotCardExchangeController : SVSimController
|
|||||||
// Debit spot points. Client-supplied exchange_point isn't authoritative — server uses
|
// Debit spot points. Client-supplied exchange_point isn't authoritative — server uses
|
||||||
// catalog price. Mirroring the build_deck/sleeve convention: post-state currency entry
|
// catalog price. Mirroring the build_deck/sleeve convention: post-state currency entry
|
||||||
// first, then grants.
|
// first, then grants.
|
||||||
if (viewer.Currency.SpotPoints < (ulong)entry.ExchangePoint)
|
var spotRes = await _spend.TrySpendAsync(viewer, SpendCurrency.SpotPoint, entry.ExchangePoint);
|
||||||
|
if (!spotRes.Success)
|
||||||
return BadRequest(new { error = "insufficient_spot_points" });
|
return BadRequest(new { error = "insufficient_spot_points" });
|
||||||
viewer.Currency.SpotPoints -= (ulong)entry.ExchangePoint;
|
|
||||||
rewardList.Add(new RewardListEntry
|
rewardList.Add(new RewardListEntry
|
||||||
{
|
{
|
||||||
RewardType = (int)UserGoodsType.SpotCardPoint,
|
RewardType = (int)UserGoodsType.SpotCardPoint,
|
||||||
RewardId = 0,
|
RewardId = 0,
|
||||||
RewardNum = checked((int)viewer.Currency.SpotPoints),
|
RewardNum = checked((int)spotRes.PostStateTotal),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Grant the card itself via the existing card dispatcher (handles cosmetic cascade).
|
// Grant the card itself via the existing card dispatcher (handles cosmetic cascade).
|
||||||
|
|||||||
Reference in New Issue
Block a user