Includes Cards/Sleeves/Emblems/LeaderSkins/Degrees/MyPageBackgrounds/Items under AsSplitQuery, plus caller-supplied extras via InventoryLoadConfig. Opens a DB transaction and returns an InventoryTransaction shell. All mutation methods throw NotImplementedException until subsequent tasks land them. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
64 lines
2.2 KiB
C#
64 lines
2.2 KiB
C#
using Microsoft.EntityFrameworkCore.Storage;
|
|
using Microsoft.Extensions.Logging;
|
|
using SVSim.Database.Enums;
|
|
using SVSim.Database.Models;
|
|
using SVSim.Database.Models.Config;
|
|
|
|
namespace SVSim.Database.Services.Inventory;
|
|
|
|
internal sealed class InventoryTransaction : IInventoryTransaction
|
|
{
|
|
private readonly SVSimDbContext _db;
|
|
private readonly IDbContextTransaction _dbTx;
|
|
private readonly ILogger _log;
|
|
private readonly FreeplayConfig _freeplay;
|
|
private bool _committed;
|
|
|
|
public Viewer Viewer { get; }
|
|
public bool IsFreeplay => _freeplay.Enabled;
|
|
|
|
public InventoryTransaction(
|
|
SVSimDbContext db,
|
|
IDbContextTransaction dbTx,
|
|
Viewer viewer,
|
|
FreeplayConfig freeplay,
|
|
ILogger log)
|
|
{
|
|
_db = db;
|
|
_dbTx = dbTx;
|
|
Viewer = viewer;
|
|
_freeplay = freeplay;
|
|
_log = log;
|
|
}
|
|
|
|
// Implementations land in later tasks. Throw NotImplementedException to keep the build green.
|
|
public Task<SpendResult> TrySpendAsync(SpendCurrency currency, long cost, CancellationToken ct = default)
|
|
=> throw new NotImplementedException();
|
|
|
|
public Task<SpendResult> TryDebitAsync(UserGoodsType type, long detailId, int num, CancellationToken ct = default)
|
|
=> throw new NotImplementedException();
|
|
|
|
public Task<IReadOnlyList<GrantedReward>> GrantAsync(UserGoodsType type, long detailId, int num, CancellationToken ct = default)
|
|
=> throw new NotImplementedException();
|
|
|
|
public Task<int> BackfillCardCosmeticsAsync(CancellationToken ct = default)
|
|
=> throw new NotImplementedException();
|
|
|
|
public long EffectiveBalance(SpendCurrency currency) => throw new NotImplementedException();
|
|
public bool OwnsCard(long cardId) => throw new NotImplementedException();
|
|
public bool OwnsCosmetic(CosmeticType type, int id) => throw new NotImplementedException();
|
|
|
|
public Task<InventoryCommitResult> CommitAsync(CancellationToken ct = default)
|
|
=> throw new NotImplementedException();
|
|
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
if (!_committed)
|
|
{
|
|
await _dbTx.RollbackAsync();
|
|
_db.ChangeTracker.Clear();
|
|
}
|
|
await _dbTx.DisposeAsync();
|
|
}
|
|
}
|