refactor(sleeve): route currency spend through CurrencySpendService
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,11 +20,13 @@ public class SleeveController : SVSimController
|
|||||||
{
|
{
|
||||||
private readonly SVSimDbContext _db;
|
private readonly SVSimDbContext _db;
|
||||||
private readonly RewardGrantService _rewards;
|
private readonly RewardGrantService _rewards;
|
||||||
|
private readonly ICurrencySpendService _spend;
|
||||||
|
|
||||||
public SleeveController(SVSimDbContext db, RewardGrantService rewards)
|
public SleeveController(SVSimDbContext db, RewardGrantService rewards, ICurrencySpendService spend)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_rewards = rewards;
|
_rewards = rewards;
|
||||||
|
_spend = spend;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("info")]
|
[HttpPost("info")]
|
||||||
@@ -122,20 +124,16 @@ public class SleeveController : SVSimController
|
|||||||
case 1: // crystal
|
case 1: // crystal
|
||||||
if (product.PriceCrystal is null)
|
if (product.PriceCrystal is null)
|
||||||
return BadRequest(new { error = "price_not_available_for_currency" });
|
return BadRequest(new { error = "price_not_available_for_currency" });
|
||||||
var crystalCost = (ulong)product.PriceCrystal.Value;
|
var crystalRes = await _spend.TrySpendAsync(viewer, SpendCurrency.Crystal, product.PriceCrystal.Value);
|
||||||
if (viewer.Currency.Crystals < crystalCost)
|
if (!crystalRes.Success) return BadRequest(new { error = "insufficient_crystals" });
|
||||||
return BadRequest(new { error = "insufficient_crystals" });
|
rewardList.Add(new RewardListEntry { RewardType = 2, RewardId = 0, RewardNum = (int)crystalRes.PostStateTotal });
|
||||||
viewer.Currency.Crystals -= crystalCost;
|
|
||||||
rewardList.Add(new RewardListEntry { RewardType = 2, RewardId = 0, RewardNum = (int)viewer.Currency.Crystals });
|
|
||||||
break;
|
break;
|
||||||
case 2: // rupy
|
case 2: // rupy
|
||||||
if (product.PriceRupy is null)
|
if (product.PriceRupy is null)
|
||||||
return BadRequest(new { error = "price_not_available_for_currency" });
|
return BadRequest(new { error = "price_not_available_for_currency" });
|
||||||
var rupyCost = (ulong)product.PriceRupy.Value;
|
var rupyRes = await _spend.TrySpendAsync(viewer, SpendCurrency.Rupee, product.PriceRupy.Value);
|
||||||
if (viewer.Currency.Rupees < rupyCost)
|
if (!rupyRes.Success) return BadRequest(new { error = "insufficient_rupees" });
|
||||||
return BadRequest(new { error = "insufficient_rupees" });
|
rewardList.Add(new RewardListEntry { RewardType = 9, RewardId = 0, RewardNum = (int)rupyRes.PostStateTotal });
|
||||||
viewer.Currency.Rupees -= rupyCost;
|
|
||||||
rewardList.Add(new RewardListEntry { RewardType = 9, RewardId = 0, RewardNum = (int)viewer.Currency.Rupees });
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user