feat(bp): repositories + identity generation for runtime-inserted tables
Add ValueGeneratedOnAdd to ViewerBattlePassProgress.Id and ViewerBattlePassClaims.Id so Postgres generates IDENTITY values at runtime. Regenerate AddBattlePass migration in-place to include the IdentityByDefaultColumn annotations. Add IBattlePassRepository / BattlePassRepository (season lookup + level-curve cache) and IViewerBattlePassRepository / ViewerBattlePassRepository (get-or-create progress, claim reads/writes). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Enums;
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.BattlePass;
|
||||
|
||||
public sealed class ViewerBattlePassRepository : IViewerBattlePassRepository
|
||||
{
|
||||
private readonly SVSimDbContext _db;
|
||||
|
||||
public ViewerBattlePassRepository(SVSimDbContext db) { _db = db; }
|
||||
|
||||
public async Task<ViewerBattlePassProgressEntry> GetOrCreateProgressAsync(long viewerId, int seasonId, CancellationToken ct)
|
||||
{
|
||||
var existing = await _db.ViewerBattlePassProgress
|
||||
.FirstOrDefaultAsync(p => p.ViewerId == viewerId && p.SeasonId == seasonId, ct);
|
||||
if (existing is not null) return existing;
|
||||
|
||||
var entry = new ViewerBattlePassProgressEntry
|
||||
{
|
||||
ViewerId = viewerId,
|
||||
SeasonId = seasonId,
|
||||
CurrentPoint = 0,
|
||||
IsPremium = false,
|
||||
WeeklyPoints = 0,
|
||||
WeeklyPeriodStart = null,
|
||||
};
|
||||
_db.ViewerBattlePassProgress.Add(entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
public Task<List<ViewerBattlePassClaimEntry>> GetClaimsAsync(long viewerId, int seasonId, CancellationToken ct) =>
|
||||
_db.ViewerBattlePassClaims.AsNoTracking()
|
||||
.Where(c => c.ViewerId == viewerId && c.SeasonId == seasonId)
|
||||
.ToListAsync(ct);
|
||||
|
||||
public void AddClaim(long viewerId, int seasonId, BattlePassTrack track, int level, DateTimeOffset claimedAt)
|
||||
{
|
||||
_db.ViewerBattlePassClaims.Add(new ViewerBattlePassClaimEntry
|
||||
{
|
||||
ViewerId = viewerId, SeasonId = seasonId, Track = track,
|
||||
Level = level, ClaimedAt = claimedAt,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user