refactor(gacha-point): route TryExchangeAsync through IInventoryTransaction

Change signature from (Viewer, packId, cardId) to (IInventoryTransaction, packId, cardId).
Drop RewardGrantService from GachaPointService ctor. PackController.ExchangeGachaPoint opens
tx with GachaPointBalances/Received extra includes, passes tx, commits on success.
Update GachaPointServiceTests to use inv.BeginAsync + tx pattern.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-31 16:55:08 -04:00
parent b6bf9b7495
commit c37c04c1b7
4 changed files with 60 additions and 60 deletions

View File

@@ -1,4 +1,5 @@
using SVSim.Database.Models;
using SVSim.Database.Services.Inventory;
using SVSim.EmulatedEntrypoint.Models.Dtos;
namespace SVSim.EmulatedEntrypoint.Services;
@@ -23,11 +24,14 @@ public interface IGachaPointService
void Accrue(Viewer viewer, PackConfigEntry pack, PackChildGachaEntry child, int packNumber);
/// <summary>
/// Validate + execute an exchange. Returns the grant outcome on success (reward_list
/// entries the controller will return in <see cref="Dtos.Responses.Pack.ExchangeGachaPointResponse"/>),
/// or a failure result describing why. Mutates the in-memory graph; caller saves.
/// Validate + execute an exchange using the provided inventory transaction (which must
/// have <c>GachaPointBalances</c> and <c>GachaPointReceived</c> loaded on <c>tx.Viewer</c>
/// via <see cref="IInventoryService.BeginAsync"/> extra includes). Grants the card via
/// the tx. Returns the grant outcome on success (reward_list entries already converted to
/// <see cref="RewardListEntry"/>), or a failure result describing why. Caller commits
/// the tx on success.
/// </summary>
Task<ExchangeOutcome> TryExchangeAsync(Viewer viewer, int packId, long cardId);
Task<ExchangeOutcome> TryExchangeAsync(IInventoryTransaction tx, int packId, long cardId);
}
public sealed record ExchangeOutcome(bool Success, string? Error, IReadOnlyList<RewardListEntry> RewardList)