feat(battle-xp): config section + viewer loader for class XP grants

Adds BattleXpConfig ([ConfigSection("BattleXp")]) with global
XpPerWin/XpPerLoss plus per-mode nullable overrides. Adds BattleXpMode
enum and IViewerRepository.LoadForBattleXpGrantAsync — focused tracked
load with viewer.Classes + Class nav ref included, for the service
about to be introduced.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-07-04 08:44:11 -04:00
parent 57df329923
commit 4541378885
4 changed files with 55 additions and 0 deletions

View File

@@ -51,6 +51,14 @@ public interface IViewerRepository
/// </summary>
Task<Models.Viewer?> LoadForMatchContextAsync(long viewerId);
/// <summary>
/// Focused load for class-XP grants: viewer with owned <c>Classes</c> collection and
/// each <c>ViewerClassData.Class</c> nav ref included. Tracked (not AsNoTracking) so
/// the caller can mutate <c>Exp</c>/<c>Level</c> and <c>SaveChangesAsync</c>. Returns
/// null if the viewer does not exist.
/// </summary>
Task<Models.Viewer?> LoadForBattleXpGrantAsync(long viewerId, CancellationToken ct = default);
/// <summary>Sets Viewer.GuildId to <paramref name="guildId"/>. No-op if the viewer does not exist.</summary>
Task SetGuildIdAsync(long viewerId, int guildId, CancellationToken ct = default);

View File

@@ -273,6 +273,14 @@ public class ViewerRepository : IViewerRepository
.FirstOrDefaultAsync(v => v.Id == viewerId);
}
public Task<Models.Viewer?> LoadForBattleXpGrantAsync(long viewerId, CancellationToken ct = default)
{
return _dbContext.Set<Models.Viewer>()
.Include(v => v.Classes)
.ThenInclude(c => c.Class)
.FirstOrDefaultAsync(v => v.Id == viewerId, ct);
}
public async Task SetGuildIdAsync(long viewerId, int guildId, CancellationToken ct = default)
{
var viewer = await _dbContext.Set<Models.Viewer>()