From 1f584613260a5f1176f34b93f4cf15ea8cbfa2a2 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Fri, 29 May 2026 14:14:14 -0400 Subject: [PATCH] refactor(sleeve): route currency spend through CurrencySpendService Co-Authored-By: Claude Sonnet 4.6 --- .../Controllers/SleeveController.cs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/SVSim.EmulatedEntrypoint/Controllers/SleeveController.cs b/SVSim.EmulatedEntrypoint/Controllers/SleeveController.cs index c9d623e..1f66091 100644 --- a/SVSim.EmulatedEntrypoint/Controllers/SleeveController.cs +++ b/SVSim.EmulatedEntrypoint/Controllers/SleeveController.cs @@ -20,11 +20,13 @@ public class SleeveController : SVSimController { private readonly SVSimDbContext _db; private readonly RewardGrantService _rewards; + private readonly ICurrencySpendService _spend; - public SleeveController(SVSimDbContext db, RewardGrantService rewards) + public SleeveController(SVSimDbContext db, RewardGrantService rewards, ICurrencySpendService spend) { _db = db; _rewards = rewards; + _spend = spend; } [HttpPost("info")] @@ -122,20 +124,16 @@ public class SleeveController : SVSimController case 1: // crystal if (product.PriceCrystal is null) return BadRequest(new { error = "price_not_available_for_currency" }); - var crystalCost = (ulong)product.PriceCrystal.Value; - if (viewer.Currency.Crystals < crystalCost) - return BadRequest(new { error = "insufficient_crystals" }); - viewer.Currency.Crystals -= crystalCost; - rewardList.Add(new RewardListEntry { RewardType = 2, RewardId = 0, RewardNum = (int)viewer.Currency.Crystals }); + var crystalRes = await _spend.TrySpendAsync(viewer, SpendCurrency.Crystal, product.PriceCrystal.Value); + if (!crystalRes.Success) return BadRequest(new { error = "insufficient_crystals" }); + rewardList.Add(new RewardListEntry { RewardType = 2, RewardId = 0, RewardNum = (int)crystalRes.PostStateTotal }); break; case 2: // rupy if (product.PriceRupy is null) return BadRequest(new { error = "price_not_available_for_currency" }); - var rupyCost = (ulong)product.PriceRupy.Value; - if (viewer.Currency.Rupees < rupyCost) - return BadRequest(new { error = "insufficient_rupees" }); - viewer.Currency.Rupees -= rupyCost; - rewardList.Add(new RewardListEntry { RewardType = 9, RewardId = 0, RewardNum = (int)viewer.Currency.Rupees }); + var rupyRes = await _spend.TrySpendAsync(viewer, SpendCurrency.Rupee, product.PriceRupy.Value); + if (!rupyRes.Success) return BadRequest(new { error = "insufficient_rupees" }); + rewardList.Add(new RewardListEntry { RewardType = 9, RewardId = 0, RewardNum = (int)rupyRes.PostStateTotal }); break; }