feat(packs): PackDrawTable aggregate + IPackDrawTableRepository
Aggregate (Config + SlotRates + CardWeights) and a single-pack getter loaded as one unit per /pack/open. PackOpenService consumes the aggregate; tests use the production seed (fixture overlay) to validate shape. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace SVSim.Database.Repositories.PackDrawTables;
|
||||
|
||||
public interface IPackDrawTableRepository
|
||||
{
|
||||
/// <summary>Returns the draw table for <paramref name="packId"/>, or null if not seeded.</summary>
|
||||
Task<PackDrawTable?> GetAsync(int packId);
|
||||
}
|
||||
14
SVSim.Database/Repositories/PackDrawTable/PackDrawTable.cs
Normal file
14
SVSim.Database/Repositories/PackDrawTable/PackDrawTable.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.PackDrawTables;
|
||||
|
||||
/// <summary>
|
||||
/// All draw data for a single pack: per-pack config + slot rates + per-card weights.
|
||||
/// Loaded as one unit by <see cref="IPackDrawTableRepository.GetAsync"/>.
|
||||
/// </summary>
|
||||
public sealed class PackDrawTable
|
||||
{
|
||||
public required PackDrawConfigEntry Config { get; init; }
|
||||
public required IReadOnlyList<PackDrawSlotRateEntry> SlotRates { get; init; }
|
||||
public required IReadOnlyList<PackDrawCardWeightEntry> CardWeights { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SVSim.Database.Repositories.PackDrawTables;
|
||||
|
||||
public class PackDrawTableRepository : IPackDrawTableRepository
|
||||
{
|
||||
private readonly SVSimDbContext _db;
|
||||
public PackDrawTableRepository(SVSimDbContext db) { _db = db; }
|
||||
|
||||
public async Task<PackDrawTable?> GetAsync(int packId)
|
||||
{
|
||||
var config = await _db.PackDrawConfigs.FirstOrDefaultAsync(c => c.Id == packId);
|
||||
if (config is null) return null;
|
||||
|
||||
var slotRates = await _db.PackDrawSlotRates
|
||||
.Where(s => s.PackId == packId)
|
||||
.ToListAsync();
|
||||
|
||||
var cardWeights = await _db.PackDrawCardWeights
|
||||
.Where(w => w.PackId == packId)
|
||||
.ToListAsync();
|
||||
|
||||
return new PackDrawTable
|
||||
{
|
||||
Config = config,
|
||||
SlotRates = slotRates,
|
||||
CardWeights = cardWeights,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user