Add database layer (EF Core + Postgres) and Blazor Server admin site
- SOR.Database: 5 bounded-context DbContexts (identity, catalog, collection, bazaar, chat), all entities/enums, JSONB for card abilities, ServiceRegistration with per-context connection string fallback to "Default" - SOR.Admin: Blazor Server (.NET 8) — card editor, account management, bazaar overview, feature flags; Identity + cookie auth; FallbackPolicy requires Admin/SuperAdmin role; login via minimal API form POST endpoint - Directory.Packages.props: add Microsoft.AspNetCore.Identity.EntityFrameworkCore - SOR.slnx: add SOR.Admin + SOR.Database to solution (11 projects, 0 errors, 0 warnings) Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
@@ -34,6 +34,8 @@
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
|
||||
<!-- Design-time tools: enables 'dotnet ef migrations add' commands -->
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0" />
|
||||
<!-- Identity with EF Core: user/role store backed by a DbContext -->
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.0" />
|
||||
|
||||
<!-- ── Logging ────────────────────────────────────────────────────────── -->
|
||||
<!-- Serilog: structured logging library (replaces Microsoft's default logger) -->
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
<Solution>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/SOR.Admin/SOR.Admin.csproj" />
|
||||
<Project Path="src/SOR.Auth/SOR.Auth.csproj" />
|
||||
<Project Path="src/SOR.Database/SOR.Database.csproj" />
|
||||
<Project Path="src/SOR.Gateway/SOR.Gateway.csproj" />
|
||||
<Project Path="src/SOR.Host/SOR.Host.csproj" />
|
||||
<Project Path="src/SOR.Networking.Abstractions/SOR.Networking.Abstractions.csproj" />
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<base href="/" />
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
|
||||
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH"
|
||||
crossorigin="anonymous" />
|
||||
<link rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css" />
|
||||
<link rel="stylesheet" href="app.css" />
|
||||
<HeadOutlet @rendermode="InteractiveServer" />
|
||||
</head>
|
||||
<body>
|
||||
<Routes @rendermode="InteractiveServer" />
|
||||
<script src="_framework/blazor.web.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,10 @@
|
||||
@inherits LayoutComponentBase
|
||||
|
||||
<div class="sor-admin-shell">
|
||||
<NavMenu />
|
||||
<main class="sor-admin-content">
|
||||
<div class="container-fluid py-4">
|
||||
@Body
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
@@ -0,0 +1,48 @@
|
||||
<nav class="sor-admin-sidebar d-flex flex-column bg-dark text-white p-3">
|
||||
<a class="navbar-brand text-white fw-bold fs-5 mb-4 text-decoration-none" href="/">
|
||||
<i class="bi bi-lightning-charge-fill text-warning me-2"></i>SOR Admin
|
||||
</a>
|
||||
|
||||
<ul class="nav nav-pills flex-column gap-1 flex-grow-1">
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/" Match="NavLinkMatch.All">
|
||||
<i class="bi bi-speedometer2 me-2"></i>Dashboard
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/cards">
|
||||
<i class="bi bi-collection me-2"></i>Cards
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/accounts">
|
||||
<i class="bi bi-people me-2"></i>Accounts
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/bazaar">
|
||||
<i class="bi bi-shop me-2"></i>Bazaar
|
||||
</NavLink>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<NavLink class="nav-link text-white" href="/feature-flags">
|
||||
<i class="bi bi-toggles me-2"></i>Feature Flags
|
||||
</NavLink>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="mt-auto pt-3 border-top border-secondary">
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="text-muted small mb-2">
|
||||
<i class="bi bi-person-circle me-1"></i>@context.User.Identity?.Name
|
||||
</div>
|
||||
<form method="post" action="/auth/logout">
|
||||
<button type="submit" class="btn btn-sm btn-outline-secondary w-100">
|
||||
<i class="bi bi-box-arrow-right me-1"></i>Sign out
|
||||
</button>
|
||||
</form>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -0,0 +1,165 @@
|
||||
@page "/accounts/{Id:guid}"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject SorIdentityDbContext Db
|
||||
@inject UserManager<Account> UserManager
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>Account – SOR Admin</PageTitle>
|
||||
|
||||
@if (_account == null)
|
||||
{
|
||||
<p class="text-muted">Loading…</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="mb-4">
|
||||
<a href="/accounts" class="text-muted text-decoration-none small">
|
||||
<i class="bi bi-arrow-left me-1"></i>Accounts
|
||||
</a>
|
||||
<h1 class="mt-1 mb-0">@(_account.DisplayName ?? _account.Email)</h1>
|
||||
<div class="text-muted small">@_account.Id</div>
|
||||
</div>
|
||||
|
||||
@if (_message != null)
|
||||
{
|
||||
<div class="alert @(_isError ? "alert-danger" : "alert-success")">@_message</div>
|
||||
}
|
||||
|
||||
<div class="row g-4">
|
||||
<!-- Profile -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Profile</div>
|
||||
<div class="card-body">
|
||||
<dl class="row mb-0">
|
||||
<dt class="col-sm-4">Email</dt>
|
||||
<dd class="col-sm-8">@_account.Email</dd>
|
||||
<dt class="col-sm-4">Display Name</dt>
|
||||
<dd class="col-sm-8">@(_account.DisplayName ?? "–")</dd>
|
||||
<dt class="col-sm-4">Created</dt>
|
||||
<dd class="col-sm-8">@_account.CreatedAt.ToString("yyyy-MM-dd HH:mm UTC")</dd>
|
||||
<dt class="col-sm-4">Last Login</dt>
|
||||
<dd class="col-sm-8">@(_account.LastLoginAt?.ToString("yyyy-MM-dd HH:mm UTC") ?? "Never")</dd>
|
||||
<dt class="col-sm-4">Email Confirmed</dt>
|
||||
<dd class="col-sm-8">@(_account.EmailConfirmed ? "Yes" : "No")</dd>
|
||||
<dt class="col-sm-4">2FA</dt>
|
||||
<dd class="col-sm-8">@(_account.TwoFactorEnabled ? "Enabled" : "Disabled")</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Roles -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Roles</div>
|
||||
<div class="card-body">
|
||||
@if (_roles.Count == 0)
|
||||
{
|
||||
<p class="text-muted small">No roles assigned.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var role in _roles)
|
||||
{
|
||||
<span class="badge bg-primary me-1 mb-1">@role</span>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Ban / Unban -->
|
||||
<div class="col-md-6">
|
||||
<div class="card shadow-sm @(_isBanned ? "border-danger" : "")">
|
||||
<div class="card-header fw-medium d-flex justify-content-between">
|
||||
<span>Account Status</span>
|
||||
@if (_isBanned)
|
||||
{
|
||||
<span class="badge bg-danger">Banned until @_account.LockoutEnd?.ToString("yyyy-MM-dd")</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-success">Active</span>
|
||||
}
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (_isBanned)
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-success" @onclick="UnbanAsync">
|
||||
<i class="bi bi-unlock me-1"></i>Unban Account
|
||||
</button>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="d-flex gap-2 align-items-end">
|
||||
<div>
|
||||
<label class="form-label small">Ban duration (days)</label>
|
||||
<input @bind="_banDays" type="number" min="1" max="36500"
|
||||
class="form-control form-control-sm" style="width:120px" />
|
||||
</div>
|
||||
<button class="btn btn-sm btn-danger" @onclick="BanAsync">
|
||||
<i class="bi bi-ban me-1"></i>Ban Account
|
||||
</button>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<button class="btn btn-sm btn-outline-danger" @onclick="BanPermanentAsync">
|
||||
Permanent Ban
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid Id { get; set; }
|
||||
|
||||
private Account? _account;
|
||||
private List<string> _roles = new();
|
||||
private bool _isBanned;
|
||||
private int _banDays = 30;
|
||||
private string? _message;
|
||||
private bool _isError;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_account = await UserManager.FindByIdAsync(Id.ToString());
|
||||
if (_account != null)
|
||||
{
|
||||
_roles = (await UserManager.GetRolesAsync(_account)).ToList();
|
||||
_isBanned = _account.LockoutEnd > DateTimeOffset.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task BanAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
await UserManager.SetLockoutEndDateAsync(
|
||||
_account, DateTimeOffset.UtcNow.AddDays(_banDays));
|
||||
_isBanned = true;
|
||||
_message = $"Account banned for {_banDays} days.";
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
private async Task BanPermanentAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
await UserManager.SetLockoutEndDateAsync(
|
||||
_account, DateTimeOffset.MaxValue);
|
||||
_isBanned = true;
|
||||
_message = "Account permanently banned.";
|
||||
_isError = false;
|
||||
}
|
||||
|
||||
private async Task UnbanAsync()
|
||||
{
|
||||
if (_account == null) return;
|
||||
await UserManager.SetLockoutEndDateAsync(_account, null);
|
||||
_isBanned = false;
|
||||
_message = "Account unbanned.";
|
||||
_isError = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
@page "/accounts"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject SorIdentityDbContext Db
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>Accounts – SOR Admin</PageTitle>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="mb-0">Accounts</h1>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-body py-2">
|
||||
<input value="@_search"
|
||||
@oninput="e => { _search = e.Value?.ToString() ?? string.Empty; Filter(); }"
|
||||
class="form-control form-control-sm" style="max-width:320px"
|
||||
placeholder="Search by email or display name…" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
@if (_accounts == null)
|
||||
{
|
||||
<p class="p-3 text-muted">Loading…</p>
|
||||
}
|
||||
else if (_accounts.Count == 0)
|
||||
{
|
||||
<p class="p-3 text-muted">No accounts found.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Email</th>
|
||||
<th>Display Name</th>
|
||||
<th>Created</th>
|
||||
<th>Last Login</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var acc in _accounts)
|
||||
{
|
||||
<tr>
|
||||
<td>@acc.Email</td>
|
||||
<td>@(acc.DisplayName ?? "–")</td>
|
||||
<td class="text-muted small">@acc.CreatedAt.ToString("yyyy-MM-dd")</td>
|
||||
<td class="text-muted small">
|
||||
@(acc.LastLoginAt?.ToString("yyyy-MM-dd") ?? "Never")
|
||||
</td>
|
||||
<td>
|
||||
@if (acc.LockoutEnd > DateTimeOffset.UtcNow)
|
||||
{
|
||||
<span class="badge bg-danger">Banned</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-success">Active</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<a class="btn btn-sm btn-outline-primary" href="/accounts/@acc.Id">
|
||||
<i class="bi bi-eye"></i> View
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<Account>? _accounts;
|
||||
private List<Account> _all = new();
|
||||
private string _search = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_all = await Db.Users
|
||||
.OrderByDescending(a => a.CreatedAt)
|
||||
.ToListAsync();
|
||||
_accounts = _all;
|
||||
}
|
||||
|
||||
private void Filter()
|
||||
{
|
||||
_accounts = _all
|
||||
.Where(a =>
|
||||
string.IsNullOrEmpty(_search) ||
|
||||
(a.Email?.Contains(_search, StringComparison.OrdinalIgnoreCase) == true) ||
|
||||
(a.DisplayName?.Contains(_search, StringComparison.OrdinalIgnoreCase) == true))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
@page "/bazaar"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject BazaarDbContext Db
|
||||
|
||||
<PageTitle>Bazaar – SOR Admin</PageTitle>
|
||||
|
||||
<h1 class="mb-4">Bazaar</h1>
|
||||
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-sm-4">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1">Active Listings</div>
|
||||
<div class="fs-3 fw-bold text-success">@(_active ?? 0)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-4">
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1">Total Transactions</div>
|
||||
<div class="fs-3 fw-bold">@(_txCount ?? 0)</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">Recent Transactions</div>
|
||||
<div class="card-body p-0">
|
||||
@if (_recentTx == null)
|
||||
{
|
||||
<p class="p-3 text-muted">Loading…</p>
|
||||
}
|
||||
else if (_recentTx.Count == 0)
|
||||
{
|
||||
<p class="p-3 text-muted">No transactions yet.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-sm table-hover mb-0">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Amount</th>
|
||||
<th>Currency</th>
|
||||
<th>Listing</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var tx in _recentTx)
|
||||
{
|
||||
<tr>
|
||||
<td>@tx.TransactedAt.ToString("yyyy-MM-dd HH:mm")</td>
|
||||
<td>@tx.Amount.ToString("N2")</td>
|
||||
<td><span class="badge bg-secondary">@tx.Currency</span></td>
|
||||
<td class="text-muted small">@tx.ListingId</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private int? _active;
|
||||
private int? _txCount;
|
||||
private List<BazaarTransaction>? _recentTx;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_active = await Db.Listings.CountAsync(l => l.Status == BazaarListingStatus.Active);
|
||||
_txCount = await Db.Transactions.CountAsync();
|
||||
_recentTx = await Db.Transactions
|
||||
.OrderByDescending(t => t.TransactedAt)
|
||||
.Take(50)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,463 @@
|
||||
@page "/cards/new"
|
||||
@page "/cards/{Id:guid}"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject CatalogDbContext Db
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>@(_isNew ? "New Card" : _card?.Name ?? "Card") – SOR Admin</PageTitle>
|
||||
|
||||
@if (_card == null)
|
||||
{
|
||||
<p class="text-muted">Loading…</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<div>
|
||||
<a href="/cards" class="text-muted text-decoration-none small">
|
||||
<i class="bi bi-arrow-left me-1"></i>Cards
|
||||
</a>
|
||||
<h1 class="mb-0 mt-1">@(_isNew ? "New Card" : _card.Name)</h1>
|
||||
</div>
|
||||
<div class="d-flex gap-2">
|
||||
@if (!_isNew)
|
||||
{
|
||||
<button class="btn btn-outline-danger btn-sm" @onclick="DeleteAsync">
|
||||
<i class="bi bi-trash"></i> Delete
|
||||
</button>
|
||||
}
|
||||
<button class="btn btn-primary" @onclick="SaveAsync" disabled="@_saving">
|
||||
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
|
||||
<i class="bi bi-floppy me-1"></i>Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (_saveError != null)
|
||||
{
|
||||
<div class="alert alert-danger">@_saveError</div>
|
||||
}
|
||||
@if (_saveSuccess)
|
||||
{
|
||||
<div class="alert alert-success">Saved successfully.</div>
|
||||
}
|
||||
|
||||
<!-- Tabs -->
|
||||
<ul class="nav nav-tabs mb-4">
|
||||
@foreach (var tab in _tabs)
|
||||
{
|
||||
<li class="nav-item">
|
||||
<button class="nav-link @(tab == _activeTab ? "active" : "")"
|
||||
@onclick="@(() => _activeTab = tab)">@tab</button>
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
|
||||
<!-- ── Basic Info ─────────────────────────────────────────────────────── -->
|
||||
@if (_activeTab == "Basic")
|
||||
{
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Name <span class="text-danger">*</span></label>
|
||||
<input @bind="_card.Name" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Card Type</label>
|
||||
<select @bind="_card.CardType" class="form-select">
|
||||
@foreach (var t in Enum.GetValues<CardType>())
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Affinity</label>
|
||||
<select @bind="_card.Affinity" class="form-select">
|
||||
@foreach (var a in Enum.GetValues<Affinity>())
|
||||
{
|
||||
<option value="@a">@a</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Description</label>
|
||||
<textarea @bind="_card.Description" class="form-control" rows="3"></textarea>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">SP Cost</label>
|
||||
<input @bind="_card.SpCost" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">ST Cost</label>
|
||||
<input @bind="_card.StCost" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Rarity</label>
|
||||
<select @bind="_card.Rarity" class="form-select">
|
||||
@foreach (var r in Enum.GetValues<CardRarity>())
|
||||
{
|
||||
<option value="@r">@r</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Collector #</label>
|
||||
<input @bind="_card.CollectorNumber" type="number" min="1" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-2 d-flex align-items-end">
|
||||
<div class="form-check">
|
||||
<input @bind="_card.IsPublished" type="checkbox" class="form-check-input" id="chkPublished" />
|
||||
<label class="form-check-label" for="chkPublished">Published</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<!-- ── Stats ──────────────────────────────────────────────────────────── -->
|
||||
else if (_activeTab == "Stats")
|
||||
{
|
||||
@if (_card.CardType is CardType.ArchSpirit or CardType.Spirit)
|
||||
{
|
||||
<div class="row g-3">
|
||||
<div class="col-12"><h6 class="text-muted">Channeling</h6></div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Min Channel Range</label>
|
||||
<input @bind="_card.MinChannelRange" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Max Channel Range</label>
|
||||
<input @bind="_card.MaxChannelRange" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
@if (_card.CardType == CardType.ArchSpirit)
|
||||
{
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Tier</label>
|
||||
<input @bind="_card.Tier" type="number" min="1" max="5" class="form-control" />
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="col-12"><h6 class="text-muted mt-2">Combat</h6></div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Attack Type</label>
|
||||
<select @bind="_card.AttackType" class="form-select">
|
||||
<option value="">– None –</option>
|
||||
@foreach (var t in Enum.GetValues<AttackType>())
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Damage</label>
|
||||
<input @bind="_card.Damage" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Health</label>
|
||||
<input @bind="_card.MaxHealth" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Defense</label>
|
||||
<input @bind="_card.MaxDefense" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Min Atk Range</label>
|
||||
<input @bind="_card.MinAttackRange" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Max Atk Range</label>
|
||||
<input @bind="_card.MaxAttackRange" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
|
||||
<div class="col-12"><h6 class="text-muted mt-2">Movement</h6></div>
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Movement Type</label>
|
||||
<select @bind="_card.MovementType" class="form-select">
|
||||
<option value="">– None –</option>
|
||||
@foreach (var t in Enum.GetValues<MovementType>())
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<label class="form-label">Move Points</label>
|
||||
<input @bind="_card.MovementPoints" type="number" min="0" class="form-control" />
|
||||
</div>
|
||||
|
||||
<div class="col-12"><h6 class="text-muted mt-2">Flags</h6></div>
|
||||
@foreach (var flag in _unitFlags)
|
||||
{
|
||||
<div class="col-md-2">
|
||||
<div class="form-check">
|
||||
<input type="checkbox" class="form-check-input"
|
||||
id="flag_@flag.Label"
|
||||
checked="@flag.Get(_card)"
|
||||
@onchange="e => flag.Set(_card, (bool)(e.Value ?? false))" />
|
||||
<label class="form-check-label" for="flag_@flag.Label">@flag.Label</label>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="col-12"><h6 class="text-muted mt-2">Genus Tags</h6></div>
|
||||
<div class="col-md-6">
|
||||
<input @bind="_genusInput" class="form-control"
|
||||
placeholder="Comma-separated tags, e.g. Elemental, Beast" />
|
||||
<div class="form-text">Stored as a Postgres text[] array.</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (_card.CardType == CardType.Terramorpha)
|
||||
{
|
||||
<div class="row g-3">
|
||||
<div class="col-md-3">
|
||||
<label class="form-label">Terramorpha Mode</label>
|
||||
<select @bind="_card.TerramorphaMode" class="form-select">
|
||||
@foreach (var m in Enum.GetValues<TerramorphaMode>())
|
||||
{
|
||||
<option value="@m">@m</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<p class="text-muted">No additional stats for @_card.CardType cards.</p>
|
||||
}
|
||||
}
|
||||
|
||||
<!-- ── Abilities / Effects ────────────────────────────────────────────── -->
|
||||
else if (_activeTab == "Abilities")
|
||||
{
|
||||
<div class="mb-2 text-muted small">
|
||||
@if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha)
|
||||
{
|
||||
<span>Effects JSON (Action[] array) — see <code>abilities.md</code> for schema.</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>Abilities JSON (AbilityDefinition[] array) — see <code>abilities.md</code> for schema.</span>
|
||||
}
|
||||
</div>
|
||||
<textarea @bind="_abilitiesJson" class="form-control font-monospace"
|
||||
rows="20" spellcheck="false"
|
||||
placeholder="[ { "type": "Active", ... } ]"></textarea>
|
||||
}
|
||||
|
||||
<!-- ── Assets ─────────────────────────────────────────────────────────── -->
|
||||
else if (_activeTab == "Assets")
|
||||
{
|
||||
<h6 class="text-muted mb-3">Static Assets</h6>
|
||||
<div class="row g-3 mb-4">
|
||||
@foreach (var asset in _card.Assets)
|
||||
{
|
||||
<div class="col-md-6">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<span class="badge bg-primary">@asset.AssetType</span>
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => RemoveAsset(asset)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</div>
|
||||
<input @bind="asset.CdnUrl" class="form-control form-control-sm"
|
||||
placeholder="https://cdn.sor.gg/…" />
|
||||
<input @bind="asset.MimeType" class="form-control form-control-sm mt-1"
|
||||
placeholder="MIME type (e.g. image/webp)" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div class="col-12">
|
||||
<div class="d-flex gap-2">
|
||||
@foreach (var t in Enum.GetValues<CardAssetType>())
|
||||
{
|
||||
<button class="btn btn-sm btn-outline-secondary"
|
||||
@onclick="() => AddAsset(t)">
|
||||
<i class="bi bi-plus-lg me-1"></i>@t
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h6 class="text-muted mb-3">Animation Bindings</h6>
|
||||
<table class="table table-sm">
|
||||
<thead><tr><th>Action</th><th>CDN URL</th><th></th></tr></thead>
|
||||
<tbody>
|
||||
@foreach (var anim in _card.AnimationBindings)
|
||||
{
|
||||
<tr>
|
||||
<td style="width:160px">
|
||||
<input @bind="anim.ActionName" class="form-control form-control-sm"
|
||||
placeholder="e.g. attack" />
|
||||
</td>
|
||||
<td>
|
||||
<input @bind="anim.AnimationCdnUrl" class="form-control form-control-sm"
|
||||
placeholder="https://cdn.sor.gg/…" />
|
||||
</td>
|
||||
<td style="width:50px">
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
@onclick="() => RemoveAnimation(anim)">
|
||||
<i class="bi bi-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="btn btn-sm btn-outline-secondary" @onclick="AddAnimation">
|
||||
<i class="bi bi-plus-lg me-1"></i>Add Animation
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
||||
@code {
|
||||
[Parameter] public Guid? Id { get; set; }
|
||||
|
||||
private CardDefinition? _card;
|
||||
private bool _isNew;
|
||||
private string _activeTab = "Basic";
|
||||
private readonly string[] _tabs = ["Basic", "Stats", "Abilities", "Assets"];
|
||||
private bool _saving;
|
||||
private string? _saveError;
|
||||
private bool _saveSuccess;
|
||||
private string _genusInput = string.Empty;
|
||||
private string _abilitiesJson = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_isNew = Id == null;
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
_card = new CardDefinition
|
||||
{
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
UpdatedAt = DateTimeOffset.UtcNow,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
_card = await Db.CardDefinitions
|
||||
.Include(c => c.Assets)
|
||||
.Include(c => c.AnimationBindings)
|
||||
.FirstOrDefaultAsync(c => c.Id == Id);
|
||||
|
||||
if (_card != null)
|
||||
{
|
||||
_genusInput = _card.Genus != null
|
||||
? string.Join(", ", _card.Genus)
|
||||
: string.Empty;
|
||||
|
||||
_abilitiesJson = _card.CardType is CardType.Repentance
|
||||
or CardType.Instinct or CardType.Terramorpha
|
||||
? _card.EffectsJson ?? string.Empty
|
||||
: _card.AbilitiesJson ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
if (_card == null) return;
|
||||
_saving = true;
|
||||
_saveError = null;
|
||||
_saveSuccess = false;
|
||||
|
||||
try
|
||||
{
|
||||
// Flush genus input to array.
|
||||
_card.Genus = string.IsNullOrWhiteSpace(_genusInput)
|
||||
? null
|
||||
: _genusInput.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
|
||||
// Flush abilities JSON to the correct column.
|
||||
if (_card.CardType is CardType.Repentance or CardType.Instinct or CardType.Terramorpha)
|
||||
_card.EffectsJson = string.IsNullOrWhiteSpace(_abilitiesJson) ? null : _abilitiesJson;
|
||||
else
|
||||
_card.AbilitiesJson = string.IsNullOrWhiteSpace(_abilitiesJson) ? null : _abilitiesJson;
|
||||
|
||||
_card.UpdatedAt = DateTimeOffset.UtcNow;
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
Db.CardDefinitions.Add(_card);
|
||||
}
|
||||
|
||||
await Db.SaveChangesAsync();
|
||||
_saveSuccess = true;
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
_isNew = false;
|
||||
Nav.NavigateTo($"/cards/{_card.Id}", replace: true);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_saveError = ex.Message;
|
||||
}
|
||||
finally
|
||||
{
|
||||
_saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DeleteAsync()
|
||||
{
|
||||
if (_card == null || _isNew) return;
|
||||
Db.CardDefinitions.Remove(_card);
|
||||
await Db.SaveChangesAsync();
|
||||
Nav.NavigateTo("/cards");
|
||||
}
|
||||
|
||||
private void AddAsset(CardAssetType type)
|
||||
=> _card!.Assets.Add(new CardAsset
|
||||
{
|
||||
CardDefinitionId = _card.Id,
|
||||
AssetType = type,
|
||||
CreatedAt = DateTimeOffset.UtcNow,
|
||||
});
|
||||
|
||||
private void RemoveAsset(CardAsset asset)
|
||||
{
|
||||
_card!.Assets.Remove(asset);
|
||||
if (asset.Id != Guid.Empty)
|
||||
Db.CardAssets.Remove(asset);
|
||||
}
|
||||
|
||||
private void AddAnimation()
|
||||
=> _card!.AnimationBindings.Add(new CardAnimationBinding
|
||||
{
|
||||
CardDefinitionId = _card.Id,
|
||||
});
|
||||
|
||||
private void RemoveAnimation(CardAnimationBinding anim)
|
||||
{
|
||||
_card!.AnimationBindings.Remove(anim);
|
||||
if (anim.Id != Guid.Empty)
|
||||
Db.AnimationBindings.Remove(anim);
|
||||
}
|
||||
|
||||
// ── Flag descriptors (avoids 10 identical checkboxes) ───────────────────
|
||||
|
||||
private sealed record FlagDescriptor(
|
||||
string Label,
|
||||
Func<CardDefinition, bool> Get,
|
||||
Action<CardDefinition, bool> Set);
|
||||
|
||||
private readonly FlagDescriptor[] _unitFlags =
|
||||
[
|
||||
new("Can Attack", c => c.CanAttack ?? false, (c, v) => c.CanAttack = v),
|
||||
new("Can Defend", c => c.CanDefend ?? false, (c, v) => c.CanDefend = v),
|
||||
new("Can Be Attacked", c => c.CanBeAttacked ?? false, (c, v) => c.CanBeAttacked = v),
|
||||
new("Can Be Blocked", c => c.CanBeBlocked ?? false, (c, v) => c.CanBeBlocked = v),
|
||||
new("Can Move", c => c.CanMove ?? false, (c, v) => c.CanMove = v),
|
||||
new("Can Be Obstructed",c => c.CanBeObstructed ?? false, (c, v) => c.CanBeObstructed = v),
|
||||
new("Requires LOS", c => c.RequiresLos ?? false, (c, v) => c.RequiresLos = v),
|
||||
new("Can Use Ability", c => c.CanUseAbility ?? false, (c, v) => c.CanUseAbility = v),
|
||||
new("Can Be Sacrificed",c => c.CanBeSacrificed ?? false, (c, v) => c.CanBeSacrificed = v),
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
@page "/cards"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject CatalogDbContext Db
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>Cards – SOR Admin</PageTitle>
|
||||
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
<h1 class="mb-0">Cards</h1>
|
||||
<a class="btn btn-primary" href="/cards/new">
|
||||
<i class="bi bi-plus-lg me-1"></i>New Card
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm mb-3">
|
||||
<div class="card-body py-2">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-4">
|
||||
<input value="@_search"
|
||||
@oninput="e => { _search = e.Value?.ToString() ?? string.Empty; Filter(); }"
|
||||
class="form-control form-control-sm" placeholder="Search by name…" />
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select @bind="_filterType" @bind:after="Filter" class="form-select form-select-sm">
|
||||
<option value="">All types</option>
|
||||
@foreach (var t in Enum.GetValues<CardType>())
|
||||
{
|
||||
<option value="@t">@t</option>
|
||||
}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<select @bind="_filterPublished" @bind:after="Filter" class="form-select form-select-sm">
|
||||
<option value="">All status</option>
|
||||
<option value="true">Published</option>
|
||||
<option value="false">Draft</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
@if (_cards == null)
|
||||
{
|
||||
<p class="p-3 text-muted">Loading…</p>
|
||||
}
|
||||
else if (_cards.Count == 0)
|
||||
{
|
||||
<p class="p-3 text-muted">No cards match the current filter.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-dark">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Type</th>
|
||||
<th>Affinity</th>
|
||||
<th>SP</th>
|
||||
<th>ST</th>
|
||||
<th>Rarity</th>
|
||||
<th>Status</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var card in _cards)
|
||||
{
|
||||
<tr>
|
||||
<td class="fw-medium">@card.Name</td>
|
||||
<td><span class="badge bg-secondary">@card.CardType</span></td>
|
||||
<td>@card.Affinity</td>
|
||||
<td>@card.SpCost</td>
|
||||
<td>@card.StCost</td>
|
||||
<td>@card.Rarity</td>
|
||||
<td>
|
||||
@if (card.IsPublished)
|
||||
{
|
||||
<span class="badge bg-success">Published</span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<span class="badge bg-warning text-dark">Draft</span>
|
||||
}
|
||||
</td>
|
||||
<td class="text-end">
|
||||
<a class="btn btn-sm btn-outline-primary" href="/cards/@card.Id">
|
||||
<i class="bi bi-pencil"></i> Edit
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private List<CardDefinition>? _cards;
|
||||
private List<CardDefinition> _all = new();
|
||||
private string _search = string.Empty;
|
||||
private string _filterType = string.Empty;
|
||||
private string _filterPublished = string.Empty;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_all = await Db.CardDefinitions
|
||||
.OrderBy(c => c.Name)
|
||||
.ToListAsync();
|
||||
_cards = _all;
|
||||
}
|
||||
|
||||
private void Filter()
|
||||
{
|
||||
_cards = _all
|
||||
.Where(c => string.IsNullOrEmpty(_search) ||
|
||||
c.Name.Contains(_search, StringComparison.OrdinalIgnoreCase))
|
||||
.Where(c => string.IsNullOrEmpty(_filterType) ||
|
||||
c.CardType.ToString() == _filterType)
|
||||
.Where(c => string.IsNullOrEmpty(_filterPublished) ||
|
||||
c.IsPublished.ToString().ToLower() == _filterPublished)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
@page "/"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
@inject CatalogDbContext CatalogDb
|
||||
@inject SorIdentityDbContext IdentityDb
|
||||
@inject BazaarDbContext BazaarDb
|
||||
|
||||
<PageTitle>Dashboard – SOR Admin</PageTitle>
|
||||
|
||||
<h1 class="mb-4">Dashboard</h1>
|
||||
|
||||
<div class="row g-4 mb-4">
|
||||
<div class="col-sm-6 col-xl-3">
|
||||
<div class="card border-0 shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1"><i class="bi bi-collection me-1"></i>Total Cards</div>
|
||||
<div class="fs-2 fw-bold">@(_totalCards?.ToString("N0") ?? "–")</div>
|
||||
<div class="text-success small">@(_publishedCards?.ToString("N0") ?? "–") published</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-xl-3">
|
||||
<div class="card border-0 shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1"><i class="bi bi-people me-1"></i>Accounts</div>
|
||||
<div class="fs-2 fw-bold">@(_totalAccounts?.ToString("N0") ?? "–")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-xl-3">
|
||||
<div class="card border-0 shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1"><i class="bi bi-shop me-1"></i>Active Listings</div>
|
||||
<div class="fs-2 fw-bold">@(_activeListings?.ToString("N0") ?? "–")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 col-xl-3">
|
||||
<div class="card border-0 shadow-sm h-100">
|
||||
<div class="card-body">
|
||||
<div class="text-muted small mb-1"><i class="bi bi-arrow-left-right me-1"></i>Transactions</div>
|
||||
<div class="fs-2 fw-bold">@(_totalTransactions?.ToString("N0") ?? "–")</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private int? _totalCards;
|
||||
private int? _publishedCards;
|
||||
private int? _totalAccounts;
|
||||
private int? _activeListings;
|
||||
private int? _totalTransactions;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_totalCards = await CatalogDb.CardDefinitions.CountAsync();
|
||||
_publishedCards = await CatalogDb.CardDefinitions.CountAsync(c => c.IsPublished);
|
||||
_totalAccounts = await IdentityDb.Users.CountAsync();
|
||||
_activeListings = await BazaarDb.Listings.CountAsync(l => l.Status == BazaarListingStatus.Active);
|
||||
_totalTransactions = await BazaarDb.Transactions.CountAsync();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
@page "/feature-flags"
|
||||
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
|
||||
|
||||
<PageTitle>Feature Flags – SOR Admin</PageTitle>
|
||||
|
||||
<h1 class="mb-4">Feature Flags</h1>
|
||||
|
||||
<div class="alert alert-info">
|
||||
<i class="bi bi-info-circle me-2"></i>
|
||||
Feature flags are stored in Redis via <code>RedisKeys.FeatureFlag(flag)</code>.
|
||||
This UI will read/write those keys once the Redis connection is wired into the admin site.
|
||||
For now, use <code>redis-cli SET feature:bazaar_enabled 1</code> directly.
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header fw-medium">OAuth Providers</div>
|
||||
<table class="table table-hover mb-0">
|
||||
<thead class="table-dark">
|
||||
<tr><th>Provider</th><th>Status</th><th>Note</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><i class="bi bi-google me-2 text-danger"></i>Google</td>
|
||||
<td><span class="badge bg-warning text-dark">Stubbed</span></td>
|
||||
<td class="text-muted small">Enable via appsettings OAuth config</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i class="bi bi-steam me-2"></i>Steam</td>
|
||||
<td><span class="badge bg-warning text-dark">Stubbed</span></td>
|
||||
<td class="text-muted small">Requires OpenID 2.0 handler</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i class="bi bi-apple me-2"></i>Apple</td>
|
||||
<td><span class="badge bg-warning text-dark">Stubbed</span></td>
|
||||
<td class="text-muted small">Requires Sign in with Apple OIDC</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><i class="bi bi-microsoft me-2 text-primary"></i>Microsoft</td>
|
||||
<td><span class="badge bg-warning text-dark">Stubbed</span></td>
|
||||
<td class="text-muted small">Enable via Azure AD app registration</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
@page "/login"
|
||||
@attribute [AllowAnonymous]
|
||||
@* Static SSR — no rendermode, keeps login available without a SignalR connection. *@
|
||||
|
||||
<PageTitle>Sign In – SOR Admin</PageTitle>
|
||||
|
||||
<div class="min-vh-100 d-flex align-items-center justify-content-center bg-dark">
|
||||
<div class="card shadow" style="width: 380px;">
|
||||
<div class="card-body p-4">
|
||||
<h1 class="h4 mb-1 fw-bold">
|
||||
<i class="bi bi-lightning-charge-fill text-warning me-2"></i>SOR Admin
|
||||
</h1>
|
||||
<p class="text-muted small mb-4">Sign in to continue</p>
|
||||
|
||||
@if (Error == "invalid")
|
||||
{
|
||||
<div class="alert alert-danger py-2">Invalid email or password.</div>
|
||||
}
|
||||
else if (Error == "locked")
|
||||
{
|
||||
<div class="alert alert-warning py-2">Account locked — try again later.</div>
|
||||
}
|
||||
|
||||
<form method="post" action="/auth/login">
|
||||
<input type="hidden" name="returnUrl" value="@ReturnUrl" />
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Email</label>
|
||||
<input name="email" type="email" class="form-control"
|
||||
placeholder="admin@example.com" required autofocus />
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="form-label">Password</label>
|
||||
<input name="password" type="password" class="form-control" required />
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100">Sign In</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[SupplyParameterFromQuery] public string? ReturnUrl { get; set; }
|
||||
[SupplyParameterFromQuery] public string? Error { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<CascadingAuthenticationState>
|
||||
<Router AppAssembly="@typeof(App).Assembly">
|
||||
<Found Context="routeData">
|
||||
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
|
||||
<NotAuthorized>
|
||||
@if (context.User.Identity?.IsAuthenticated != true)
|
||||
{
|
||||
<meta http-equiv="refresh" content="0;url=/login" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="container mt-5">
|
||||
<div class="alert alert-danger">
|
||||
<strong>Access denied.</strong>
|
||||
You do not have permission to view this page.
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</NotAuthorized>
|
||||
</AuthorizeRouteView>
|
||||
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
|
||||
</Found>
|
||||
<NotFound>
|
||||
<PageTitle>Not found</PageTitle>
|
||||
<LayoutView Layout="@typeof(MainLayout)">
|
||||
<div class="container mt-5">
|
||||
<div class="alert alert-warning">
|
||||
<strong>404</strong> — Nothing at this address.
|
||||
</div>
|
||||
</div>
|
||||
</LayoutView>
|
||||
</NotFound>
|
||||
</Router>
|
||||
</CascadingAuthenticationState>
|
||||
@@ -0,0 +1,20 @@
|
||||
@using System.Net.Http
|
||||
@using System.Net.Http.Json
|
||||
@using Microsoft.AspNetCore.Authorization
|
||||
@using Microsoft.AspNetCore.Identity
|
||||
@using Microsoft.AspNetCore.Components.Authorization
|
||||
@using Microsoft.AspNetCore.Components.Forms
|
||||
@using Microsoft.AspNetCore.Components.Routing
|
||||
@using Microsoft.AspNetCore.Components.Web
|
||||
@using static Microsoft.AspNetCore.Components.Web.RenderMode
|
||||
@using Microsoft.AspNetCore.Components.Web.Virtualization
|
||||
@using Microsoft.EntityFrameworkCore
|
||||
@using SOR.Admin.Components
|
||||
@using SOR.Admin.Components.Layout
|
||||
@using SOR.Database.Contexts
|
||||
@using SOR.Database.Entities.Catalog
|
||||
@using SOR.Database.Entities.Identity
|
||||
@using SOR.Database.Entities.Collection
|
||||
@using SOR.Database.Entities.Bazaar
|
||||
@using SOR.Database.Entities.Chat
|
||||
@using SOR.Database.Enums
|
||||
@@ -0,0 +1,44 @@
|
||||
namespace SOR.Admin;
|
||||
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Server;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Revalidates the Identity cookie on a schedule while a Blazor Server circuit
|
||||
/// is open, so that bans or role changes take effect without a page reload.
|
||||
/// This is the standard pattern from the Blazor Identity scaffolding.
|
||||
/// </summary>
|
||||
internal sealed class IdentityRevalidatingAuthenticationStateProvider(
|
||||
ILoggerFactory loggerFactory,
|
||||
IServiceScopeFactory scopeFactory,
|
||||
IOptions<IdentityOptions> options)
|
||||
: RevalidatingServerAuthenticationStateProvider(loggerFactory)
|
||||
{
|
||||
protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30);
|
||||
|
||||
protected override async Task<bool> ValidateAuthenticationStateAsync(
|
||||
AuthenticationState authenticationState,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
await using var scope = scopeFactory.CreateAsyncScope();
|
||||
var userManager = scope.ServiceProvider.GetRequiredService<UserManager<Account>>();
|
||||
return await ValidateSecurityStampAsync(userManager, authenticationState.User);
|
||||
}
|
||||
|
||||
private async Task<bool> ValidateSecurityStampAsync(
|
||||
UserManager<Account> userManager,
|
||||
System.Security.Claims.ClaimsPrincipal principal)
|
||||
{
|
||||
var user = await userManager.GetUserAsync(principal);
|
||||
if (user is null) return false;
|
||||
if (!userManager.SupportsUserSecurityStamp) return true;
|
||||
|
||||
var principalStamp = principal
|
||||
.FindFirst(options.Value.ClaimsIdentity.SecurityStampClaimType)?.Value;
|
||||
var userStamp = await userManager.GetSecurityStampAsync(user);
|
||||
return principalStamp == userStamp;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using Microsoft.AspNetCore.Authentication.Cookies;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SOR.Admin;
|
||||
using SOR.Admin.Components;
|
||||
using SOR.Database;
|
||||
using SOR.Database.Contexts;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// ── Blazor Server ──────────────────────────────────────────────────────────
|
||||
builder.Services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
|
||||
// Required for <AuthorizeView> and [Authorize] in Blazor components.
|
||||
builder.Services.AddCascadingAuthenticationState();
|
||||
builder.Services.AddScoped<AuthenticationStateProvider,
|
||||
IdentityRevalidatingAuthenticationStateProvider>();
|
||||
|
||||
// ── Identity + Cookie Auth ──────────────────────────────────────────────────
|
||||
builder.Services.AddAuthentication(options =>
|
||||
{
|
||||
options.DefaultScheme = IdentityConstants.ApplicationScheme;
|
||||
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
|
||||
})
|
||||
.AddIdentityCookies();
|
||||
|
||||
// Redirect to /login instead of the default /Account/Login.
|
||||
builder.Services.ConfigureApplicationCookie(options =>
|
||||
{
|
||||
options.LoginPath = "/login";
|
||||
options.AccessDeniedPath = "/login";
|
||||
options.SlidingExpiration = true;
|
||||
options.ExpireTimeSpan = TimeSpan.FromHours(8);
|
||||
});
|
||||
|
||||
// All Blazor pages require Admin or SuperAdmin role by default.
|
||||
// Override per-page with [AllowAnonymous] (login page only).
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
options.FallbackPolicy = new AuthorizationPolicyBuilder()
|
||||
.RequireAuthenticatedUser()
|
||||
.RequireRole("Admin", "SuperAdmin")
|
||||
.Build();
|
||||
});
|
||||
|
||||
builder.Services.AddIdentityCore<Account>(options =>
|
||||
{
|
||||
options.SignIn.RequireConfirmedAccount = false;
|
||||
options.Password.RequireDigit = true;
|
||||
options.Password.RequireUppercase = true;
|
||||
options.Password.RequireNonAlphanumeric = true;
|
||||
options.Password.RequiredLength = 12;
|
||||
options.Lockout.MaxFailedAccessAttempts = 5;
|
||||
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
|
||||
})
|
||||
.AddRoles<IdentityRole<Guid>>()
|
||||
.AddEntityFrameworkStores<SorIdentityDbContext>()
|
||||
.AddSignInManager()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
// ── Razor Pages (used for login/logout form posts) ─────────────────────────
|
||||
builder.Services.AddRazorPages();
|
||||
|
||||
// ── Databases ─────────────────────────────────────────────────────────────
|
||||
builder.Services.AddIdentityDatabase(builder.Configuration);
|
||||
builder.Services.AddCatalogDatabase(builder.Configuration);
|
||||
builder.Services.AddCollectionDatabase(builder.Configuration);
|
||||
builder.Services.AddBazaarDatabase(builder.Configuration);
|
||||
builder.Services.AddChatDatabase(builder.Configuration);
|
||||
|
||||
// ── HTTP pipeline ─────────────────────────────────────────────────────────
|
||||
var app = builder.Build();
|
||||
|
||||
if (!app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
app.UseHsts();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
app.UseAntiforgery();
|
||||
|
||||
// ── Auth endpoints (form POST targets — cookies cannot be set from Blazor) ──
|
||||
|
||||
// Login: called by the /login page form.
|
||||
app.MapPost("/auth/login", async (
|
||||
HttpContext ctx,
|
||||
[FromForm] string email,
|
||||
[FromForm] string password,
|
||||
[FromForm] string? returnUrl,
|
||||
UserManager<Account> userManager,
|
||||
SignInManager<Account> signInManager) =>
|
||||
{
|
||||
var user = await userManager.FindByEmailAsync(email);
|
||||
if (user is not null)
|
||||
{
|
||||
var result = await signInManager.PasswordSignInAsync(
|
||||
user, password, isPersistent: false, lockoutOnFailure: true);
|
||||
if (result.Succeeded)
|
||||
return Results.LocalRedirect(
|
||||
string.IsNullOrWhiteSpace(returnUrl) ? "/" : returnUrl);
|
||||
if (result.IsLockedOut)
|
||||
return Results.Redirect("/login?error=locked");
|
||||
}
|
||||
return Results.Redirect("/login?error=invalid");
|
||||
}).AllowAnonymous().DisableAntiforgery();
|
||||
|
||||
// Logout: called by the nav menu form.
|
||||
app.MapPost("/auth/logout", async (SignInManager<Account> signInManager) =>
|
||||
{
|
||||
await signInManager.SignOutAsync();
|
||||
return Results.Redirect("/login");
|
||||
}).DisableAntiforgery();
|
||||
|
||||
// ── Blazor + Razor Pages ──────────────────────────────────────────────────
|
||||
app.MapRazorPages();
|
||||
app.MapRazorComponents<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SOR.Admin</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Design-time only: enables 'dotnet ef migrations add' targeting this project -->
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
||||
<ProjectReference Include="..\SOR.Database\SOR.Database.csproj" />
|
||||
<ProjectReference Include="..\SOR.Shared\SOR.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
// All contexts share one Postgres database ("sor") with separate schemas.
|
||||
// Override individual keys (e.g. "Catalog") to move a schema to its own server.
|
||||
"ConnectionStrings": {
|
||||
"Default": "Host=172.10.1.127;Port=5432;Database=sor;Username=SOR-DBA;Password=G073gxq7VtQaOfnITcxDh3bsibcipe6D"
|
||||
},
|
||||
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
|
||||
}
|
||||
},
|
||||
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/* SOR Admin shell layout */
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.sor-admin-shell {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sor-admin-sidebar {
|
||||
width: 220px;
|
||||
min-width: 220px;
|
||||
overflow-y: auto;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sor-admin-content {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
background: #f8f9fa;
|
||||
}
|
||||
|
||||
/* Active nav link highlight */
|
||||
.sor-admin-sidebar .nav-link.active {
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.sor-admin-sidebar .nav-link:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
/* Monospace JSON editor */
|
||||
.font-monospace {
|
||||
font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Bazaar;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the bazaar schema: listings and transaction history.
|
||||
///
|
||||
/// Schema: "bazaar"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context BazaarDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Bazaar
|
||||
/// </summary>
|
||||
public sealed class BazaarDbContext : DbContext
|
||||
{
|
||||
public BazaarDbContext(DbContextOptions<BazaarDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<BazaarListing> Listings => Set<BazaarListing>();
|
||||
public DbSet<BazaarTransaction> Transactions => Set<BazaarTransaction>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("bazaar");
|
||||
|
||||
builder.Entity<BazaarListing>(e =>
|
||||
{
|
||||
e.ToTable("listings");
|
||||
e.HasKey(l => l.Id);
|
||||
e.Property(l => l.ListingType).HasConversion<string>();
|
||||
e.Property(l => l.Currency).HasConversion<string>();
|
||||
e.Property(l => l.Status).HasConversion<string>();
|
||||
e.Property(l => l.Price).HasColumnType("numeric(18,4)");
|
||||
e.HasIndex(l => l.SellerAccountId);
|
||||
e.HasIndex(l => new { l.Status, l.CardDefinitionId });
|
||||
e.HasIndex(l => new { l.Status, l.ExpiresAt });
|
||||
e.HasMany(l => l.Transactions)
|
||||
.WithOne(t => t.Listing)
|
||||
.HasForeignKey(t => t.ListingId)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
});
|
||||
|
||||
builder.Entity<BazaarTransaction>(e =>
|
||||
{
|
||||
e.ToTable("transactions");
|
||||
e.HasKey(t => t.Id);
|
||||
e.Property(t => t.Currency).HasConversion<string>();
|
||||
e.Property(t => t.Amount).HasColumnType("numeric(18,4)");
|
||||
e.HasIndex(t => t.BuyerAccountId);
|
||||
e.HasIndex(t => t.SellerAccountId);
|
||||
e.HasIndex(t => t.TransactedAt);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Catalog;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the catalog schema: card definitions, sets, and assets.
|
||||
/// This is read-heavy in production (clients and game servers read cards constantly)
|
||||
/// and write-heavy only from the admin tool.
|
||||
///
|
||||
/// Schema: "catalog"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context CatalogDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Catalog
|
||||
/// </summary>
|
||||
public sealed class CatalogDbContext : DbContext
|
||||
{
|
||||
public CatalogDbContext(DbContextOptions<CatalogDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<CardSet> CardSets => Set<CardSet>();
|
||||
public DbSet<CardDefinition> CardDefinitions => Set<CardDefinition>();
|
||||
public DbSet<CardAsset> CardAssets => Set<CardAsset>();
|
||||
public DbSet<CardAnimationBinding> AnimationBindings => Set<CardAnimationBinding>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("catalog");
|
||||
|
||||
builder.Entity<CardSet>(e =>
|
||||
{
|
||||
e.ToTable("card_sets");
|
||||
e.HasKey(s => s.Id);
|
||||
e.HasIndex(s => s.Code).IsUnique();
|
||||
e.HasMany(s => s.Cards)
|
||||
.WithOne(c => c.Set)
|
||||
.HasForeignKey(c => c.SetId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
});
|
||||
|
||||
builder.Entity<CardDefinition>(e =>
|
||||
{
|
||||
e.ToTable("card_definitions");
|
||||
e.HasKey(c => c.Id);
|
||||
|
||||
// Store enums as strings for readability in the DB and JSONB payloads.
|
||||
e.Property(c => c.CardType).HasConversion<string>();
|
||||
e.Property(c => c.Affinity).HasConversion<string>();
|
||||
e.Property(c => c.AttackType).HasConversion<string>();
|
||||
e.Property(c => c.MovementType).HasConversion<string>();
|
||||
e.Property(c => c.TerramorphaMode).HasConversion<string>();
|
||||
e.Property(c => c.Rarity).HasConversion<string>();
|
||||
|
||||
// JSONB columns — serialized by the service layer.
|
||||
e.Property(c => c.AbilitiesJson)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("abilities");
|
||||
e.Property(c => c.EffectsJson)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("effects");
|
||||
e.Property(c => c.OtherCostsJson)
|
||||
.HasColumnType("jsonb")
|
||||
.HasColumnName("other_costs");
|
||||
|
||||
// Postgres native text[] array for genus tags.
|
||||
e.Property(c => c.Genus).HasColumnType("text[]");
|
||||
|
||||
// Indexes for the most common query patterns.
|
||||
e.HasIndex(c => c.Name);
|
||||
e.HasIndex(c => c.CardType);
|
||||
e.HasIndex(c => c.Affinity);
|
||||
e.HasIndex(c => c.Rarity);
|
||||
e.HasIndex(c => new { c.IsPublished, c.SetId });
|
||||
|
||||
e.HasMany(c => c.Assets)
|
||||
.WithOne(a => a.CardDefinition)
|
||||
.HasForeignKey(a => a.CardDefinitionId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasMany(c => c.AnimationBindings)
|
||||
.WithOne(a => a.CardDefinition)
|
||||
.HasForeignKey(a => a.CardDefinitionId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
builder.Entity<CardAsset>(e =>
|
||||
{
|
||||
e.ToTable("card_assets");
|
||||
e.HasKey(a => a.Id);
|
||||
e.Property(a => a.AssetType).HasConversion<string>();
|
||||
e.HasIndex(a => new { a.CardDefinitionId, a.AssetType });
|
||||
});
|
||||
|
||||
builder.Entity<CardAnimationBinding>(e =>
|
||||
{
|
||||
e.ToTable("card_animation_bindings");
|
||||
e.HasKey(a => a.Id);
|
||||
// One action name per card — no duplicate "attack" bindings.
|
||||
e.HasIndex(a => new { a.CardDefinitionId, a.ActionName }).IsUnique();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Chat;
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the chat schema.
|
||||
/// At scale, high-frequency chat messages may be offloaded to a time-series store;
|
||||
/// this table serves as the durable audit log and history retrieval source.
|
||||
///
|
||||
/// Schema: "chat"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context ChatDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Chat
|
||||
/// </summary>
|
||||
public sealed class ChatDbContext : DbContext
|
||||
{
|
||||
public ChatDbContext(DbContextOptions<ChatDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<ChatChannel> Channels => Set<ChatChannel>();
|
||||
public DbSet<ChatMember> Members => Set<ChatMember>();
|
||||
public DbSet<ChatMessage> Messages => Set<ChatMessage>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("chat");
|
||||
|
||||
builder.Entity<ChatChannel>(e =>
|
||||
{
|
||||
e.ToTable("channels");
|
||||
e.HasKey(c => c.Id);
|
||||
e.Property(c => c.ChannelType).HasConversion<string>();
|
||||
e.HasIndex(c => c.ChannelType);
|
||||
e.HasIndex(c => c.MatchId);
|
||||
e.HasMany(c => c.Members)
|
||||
.WithOne(m => m.Channel)
|
||||
.HasForeignKey(m => m.ChannelId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
e.HasMany(c => c.Messages)
|
||||
.WithOne(m => m.Channel)
|
||||
.HasForeignKey(m => m.ChannelId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
builder.Entity<ChatMember>(e =>
|
||||
{
|
||||
e.ToTable("members");
|
||||
e.HasKey(m => m.Id);
|
||||
e.HasIndex(m => new { m.ChannelId, m.AccountId }).IsUnique();
|
||||
e.HasIndex(m => m.AccountId);
|
||||
});
|
||||
|
||||
builder.Entity<ChatMessage>(e =>
|
||||
{
|
||||
e.ToTable("messages");
|
||||
e.HasKey(m => m.Id);
|
||||
e.HasIndex(m => new { m.ChannelId, m.SentAt });
|
||||
e.HasIndex(m => m.SenderAccountId);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the collection schema: player-owned cards and decks.
|
||||
/// All cross-schema IDs (AccountId, CardDefinitionId) are bare Guids — no EF FKs.
|
||||
///
|
||||
/// Schema: "collection"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context CollectionDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Collection
|
||||
/// </summary>
|
||||
public sealed class CollectionDbContext : DbContext
|
||||
{
|
||||
public CollectionDbContext(DbContextOptions<CollectionDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<PlayerCard> PlayerCards => Set<PlayerCard>();
|
||||
public DbSet<Deck> Decks => Set<Deck>();
|
||||
public DbSet<DeckCard> DeckCards => Set<DeckCard>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
builder.HasDefaultSchema("collection");
|
||||
|
||||
builder.Entity<PlayerCard>(e =>
|
||||
{
|
||||
e.ToTable("player_cards");
|
||||
e.HasKey(c => c.Id);
|
||||
e.HasIndex(c => c.AccountId);
|
||||
e.HasIndex(c => new { c.AccountId, c.CardDefinitionId });
|
||||
});
|
||||
|
||||
builder.Entity<Deck>(e =>
|
||||
{
|
||||
e.ToTable("decks");
|
||||
e.HasKey(d => d.Id);
|
||||
e.HasIndex(d => d.AccountId);
|
||||
e.HasMany(d => d.Cards)
|
||||
.WithOne(dc => dc.Deck)
|
||||
.HasForeignKey(dc => dc.DeckId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
builder.Entity<DeckCard>(e =>
|
||||
{
|
||||
e.ToTable("deck_cards");
|
||||
e.HasKey(dc => dc.Id);
|
||||
// Same card definition can only appear once per deck row (use Quantity for copies).
|
||||
e.HasIndex(dc => new { dc.DeckId, dc.CardDefinitionId }).IsUnique();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
namespace SOR.Database.Contexts;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// EF Core DbContext for the identity schema.
|
||||
/// Extends IdentityDbContext so ASP.NET Core Identity manages users, roles,
|
||||
/// claims, external logins, and tokens. We add AccountSession for explicit
|
||||
/// session revocation.
|
||||
///
|
||||
/// Schema: "identity"
|
||||
/// Run migrations: dotnet ef migrations add InitialCreate
|
||||
/// --context SorIdentityDbContext
|
||||
/// --project src/SOR.Database
|
||||
/// --startup-project src/SOR.Admin
|
||||
/// --output-dir Migrations/Identity
|
||||
/// </summary>
|
||||
public sealed class SorIdentityDbContext
|
||||
: IdentityDbContext<Account, IdentityRole<Guid>, Guid>
|
||||
{
|
||||
public SorIdentityDbContext(DbContextOptions<SorIdentityDbContext> options)
|
||||
: base(options) { }
|
||||
|
||||
public DbSet<AccountSession> AccountSessions => Set<AccountSession>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
// MUST call base — Identity configures its own tables here.
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
builder.HasDefaultSchema("identity");
|
||||
|
||||
// Rename Identity's default AspNet* tables to snake_case.
|
||||
builder.Entity<Account>().ToTable("accounts");
|
||||
builder.Entity<IdentityRole<Guid>>().ToTable("roles");
|
||||
builder.Entity<IdentityUserRole<Guid>>().ToTable("account_roles");
|
||||
builder.Entity<IdentityUserClaim<Guid>>().ToTable("account_claims");
|
||||
builder.Entity<IdentityUserLogin<Guid>>().ToTable("external_logins");
|
||||
builder.Entity<IdentityRoleClaim<Guid>>().ToTable("role_claims");
|
||||
builder.Entity<IdentityUserToken<Guid>>().ToTable("account_tokens");
|
||||
|
||||
builder.Entity<Account>(e =>
|
||||
{
|
||||
e.HasIndex(a => a.DisplayName);
|
||||
});
|
||||
|
||||
builder.Entity<AccountSession>(e =>
|
||||
{
|
||||
e.ToTable("account_sessions");
|
||||
e.HasKey(s => s.Id);
|
||||
// Hash lookup must be unique and fast.
|
||||
e.HasIndex(s => s.TokenHash).IsUnique();
|
||||
// Compound index: find all active sessions for an account quickly.
|
||||
e.HasIndex(s => new { s.AccountId, s.ExpiresAt });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Bazaar;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// A player's offer to sell a card on the bazaar.
|
||||
///
|
||||
/// CardDefinitionId is denormalized (also on PlayerCard) to allow efficient
|
||||
/// filtering/searching without joining to the collection schema.
|
||||
///
|
||||
/// All cross-schema Guids have no EF FKs by design.
|
||||
/// </summary>
|
||||
public sealed class BazaarListing
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Cross-schema: seller's account.</summary>
|
||||
public Guid SellerAccountId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: the specific card instance being listed.</summary>
|
||||
public Guid PlayerCardId { get; set; }
|
||||
|
||||
/// <summary>Denormalized from PlayerCard for query performance.</summary>
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
public BazaarListingType ListingType { get; set; }
|
||||
public decimal Price { get; set; }
|
||||
public BazaarCurrency Currency { get; set; }
|
||||
public DateTimeOffset ListedAt { get; set; }
|
||||
public DateTimeOffset? ExpiresAt { get; set; }
|
||||
public BazaarListingStatus Status { get; set; } = BazaarListingStatus.Active;
|
||||
|
||||
public ICollection<BazaarTransaction> Transactions { get; set; } = new List<BazaarTransaction>();
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace SOR.Database.Entities.Bazaar;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Immutable record of a completed bazaar sale.
|
||||
/// Created when a listing transitions to Sold status.
|
||||
/// Never updated or deleted — the full audit trail is preserved.
|
||||
/// </summary>
|
||||
public sealed class BazaarTransaction
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid ListingId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: buyer's account.</summary>
|
||||
public Guid BuyerAccountId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: seller's account (denormalized from listing).</summary>
|
||||
public Guid SellerAccountId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: the card instance that changed hands.</summary>
|
||||
public Guid PlayerCardId { get; set; }
|
||||
|
||||
public decimal Amount { get; set; }
|
||||
public BazaarCurrency Currency { get; set; }
|
||||
public DateTimeOffset TransactedAt { get; set; }
|
||||
|
||||
public BazaarListing Listing { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
/// <summary>
|
||||
/// Binds a named in-game action to an animation CDN asset for a specific card.
|
||||
///
|
||||
/// ActionName is a free-form string matching the action identifiers used by the
|
||||
/// game engine and client renderer, e.g.:
|
||||
/// "idle", "attack", "defend", "death", "channel",
|
||||
/// "ability_0", "ability_1" (per ability index),
|
||||
/// "ascend", "transition"
|
||||
///
|
||||
/// This keeps animation bindings flexible — adding new action types requires
|
||||
/// no schema change, only a new row per card.
|
||||
/// </summary>
|
||||
public sealed class CardAnimationBinding
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Action identifier string as expected by the client renderer.
|
||||
/// Examples: "idle", "attack", "death", "ability_0", "ascend".
|
||||
/// </summary>
|
||||
public string ActionName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>CDN URL to the animation file (glTF animation, Spine, etc.).</summary>
|
||||
public string AnimationCdnUrl { get; set; } = string.Empty;
|
||||
|
||||
public CardDefinition CardDefinition { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// Links a card definition to one of its static CDN assets (2D art or 3D model).
|
||||
/// A card may have multiple assets of different types (e.g. one Art2D + one Model3D).
|
||||
/// Animations are separate — see CardAnimationBinding.
|
||||
/// </summary>
|
||||
public sealed class CardAsset
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
public CardAssetType AssetType { get; set; }
|
||||
|
||||
/// <summary>Full CDN URL, e.g. https://cdn.sor.gg/cards/{id}/art.webp</summary>
|
||||
public string CdnUrl { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>MIME type of the asset, e.g. image/webp, model/gltf-binary.</summary>
|
||||
public string? MimeType { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public CardDefinition CardDefinition { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// The immutable definition of a card — what it IS, not who owns a copy.
|
||||
///
|
||||
/// Core stats are stored as typed columns for fast filtering and sorting
|
||||
/// (name, type, affinity, costs, combat stats).
|
||||
///
|
||||
/// The ability/effect system is highly recursive and type-specific, so it is
|
||||
/// stored as JSONB. The game engine and admin tool own serialization.
|
||||
/// AbilitiesJson: used by ArchSpirit, Spirit, Ruin.
|
||||
/// EffectsJson: used by Repentance, Instinct, Terramorpha.
|
||||
///
|
||||
/// Genus tags are stored as a Postgres text[] array — fast for containment
|
||||
/// queries (@>) without the overhead of a junction table.
|
||||
/// </summary>
|
||||
public sealed class CardDefinition
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
// ── Shared (all card types) ─────────────────────────────────────────────
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public CardType CardType { get; set; }
|
||||
public Affinity Affinity { get; set; }
|
||||
public int SpCost { get; set; }
|
||||
public int StCost { get; set; }
|
||||
|
||||
/// <summary>JSONB: additional non-SP/ST costs (e.g. discard a card).</summary>
|
||||
public string? OtherCostsJson { get; set; }
|
||||
|
||||
// ── Unit properties (ArchSpirit + Spirit) ───────────────────────────────
|
||||
public int? MinChannelRange { get; set; }
|
||||
public int? MaxChannelRange { get; set; }
|
||||
public AttackType? AttackType { get; set; }
|
||||
public bool? RequiresLos { get; set; }
|
||||
public int? MinAttackRange { get; set; }
|
||||
public int? MaxAttackRange { get; set; }
|
||||
public bool? CanAttack { get; set; }
|
||||
public int? Damage { get; set; }
|
||||
public bool? CanDefend { get; set; }
|
||||
public int? MaxHealth { get; set; }
|
||||
public int? MaxDefense { get; set; }
|
||||
public bool? CanBeAttacked { get; set; }
|
||||
public bool? CanBeBlocked { get; set; }
|
||||
public bool? CanMove { get; set; }
|
||||
public MovementType? MovementType { get; set; }
|
||||
public int? MovementPoints { get; set; }
|
||||
public bool? CanBeObstructed { get; set; }
|
||||
public bool? CanUseAbility { get; set; }
|
||||
|
||||
/// <summary>Postgres text[]: genus classification tags (e.g. "Elemental", "Beast").</summary>
|
||||
public string[]? Genus { get; set; }
|
||||
|
||||
// ── Spirit-only ─────────────────────────────────────────────────────────
|
||||
public bool? CanBeSacrificed { get; set; }
|
||||
|
||||
// ── ArchSpirit-only ─────────────────────────────────────────────────────
|
||||
/// <summary>Tier 1 = base form; higher tiers reached via Ascend/Transition.</summary>
|
||||
public int? Tier { get; set; }
|
||||
|
||||
// ── Terramorpha-only ────────────────────────────────────────────────────
|
||||
public TerramorphaMode? TerramorphaMode { get; set; }
|
||||
|
||||
// ── Ability / Effect data (JSONB) ────────────────────────────────────────
|
||||
/// <summary>JSONB array of AbilityDefinition objects (ArchSpirit, Spirit, Ruin).</summary>
|
||||
public string? AbilitiesJson { get; set; }
|
||||
|
||||
/// <summary>JSONB array of Action objects (Repentance, Instinct, Terramorpha).</summary>
|
||||
public string? EffectsJson { get; set; }
|
||||
|
||||
// ── Publishing metadata ──────────────────────────────────────────────────
|
||||
public CardRarity Rarity { get; set; } = CardRarity.Common;
|
||||
public Guid? SetId { get; set; }
|
||||
public int? CollectorNumber { get; set; }
|
||||
|
||||
/// <summary>Only published cards are visible in the client and available for collection.</summary>
|
||||
public bool IsPublished { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
// ── Navigation ───────────────────────────────────────────────────────────
|
||||
public CardSet? Set { get; set; }
|
||||
public ICollection<CardAsset> Assets { get; set; } = new List<CardAsset>();
|
||||
public ICollection<CardAnimationBinding> AnimationBindings { get; set; } = new List<CardAnimationBinding>();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace SOR.Database.Entities.Catalog;
|
||||
|
||||
/// <summary>
|
||||
/// A named release of cards (base set, expansion, promo, etc.).
|
||||
/// Cards reference their set for collector numbering and filtering.
|
||||
/// </summary>
|
||||
public sealed class CardSet
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Human-readable set name, e.g. "Core Set", "Shattered Realms".</summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>Short uppercase code used in collector numbers, e.g. "BASE", "SR1".</summary>
|
||||
public string Code { get; set; } = string.Empty;
|
||||
|
||||
public string? Description { get; set; }
|
||||
|
||||
public DateOnly? ReleaseDate { get; set; }
|
||||
|
||||
/// <summary>Whether the set is currently active / legal for play.</summary>
|
||||
public bool IsActive { get; set; }
|
||||
|
||||
public ICollection<CardDefinition> Cards { get; set; } = new List<CardDefinition>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
using SOR.Database.Enums;
|
||||
|
||||
public sealed class ChatChannel
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public ChatChannelType ChannelType { get; set; }
|
||||
|
||||
/// <summary>For Match channels: the match ID this channel belongs to.</summary>
|
||||
public string? MatchId { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
public ICollection<ChatMember> Members { get; set; } = new List<ChatMember>();
|
||||
public ICollection<ChatMessage> Messages { get; set; } = new List<ChatMessage>();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
public sealed class ChatMember
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid ChannelId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
public DateTimeOffset JoinedAt { get; set; }
|
||||
|
||||
/// <summary>Set when the member explicitly leaves or is removed.</summary>
|
||||
public DateTimeOffset? LeftAt { get; set; }
|
||||
|
||||
public ChatChannel Channel { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace SOR.Database.Entities.Chat;
|
||||
|
||||
public sealed class ChatMessage
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid ChannelId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid SenderAccountId { get; set; }
|
||||
|
||||
public string Content { get; set; } = string.Empty;
|
||||
public DateTimeOffset SentAt { get; set; }
|
||||
public DateTimeOffset? EditedAt { get; set; }
|
||||
|
||||
/// <summary>Soft-delete: content is cleared but the row is kept for audit.</summary>
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public ChatChannel Channel { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// A named deck belonging to a player.
|
||||
/// Each deck has exactly one ArchSpirit and any number of other cards.
|
||||
/// IsValid is set by the server after validating against current deck construction rules.
|
||||
/// </summary>
|
||||
public sealed class Deck
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Owner. Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string? Description { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ArchSpirit card definition this deck is built around.
|
||||
/// Cross-schema: no EF FK to catalog.card_definitions.
|
||||
/// </summary>
|
||||
public Guid ArchSpiritCardDefinitionId { get; set; }
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// True when last validated against deck construction rules.
|
||||
/// Re-validated on each change and at match start.
|
||||
/// </summary>
|
||||
public bool IsValid { get; set; }
|
||||
|
||||
public ICollection<DeckCard> Cards { get; set; } = new List<DeckCard>();
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// One card slot in a deck: which card definition and how many copies.
|
||||
/// Cross-schema: CardDefinitionId is a bare Guid with no EF FK.
|
||||
/// </summary>
|
||||
public sealed class DeckCard
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid DeckId { get; set; }
|
||||
|
||||
/// <summary>Cross-schema: no EF FK to catalog.card_definitions.</summary>
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
public int Quantity { get; set; } = 1;
|
||||
|
||||
public Deck Deck { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
namespace SOR.Database.Entities.Collection;
|
||||
|
||||
/// <summary>
|
||||
/// One physical copy of a card owned by a player.
|
||||
///
|
||||
/// CardDefinitionId references the catalog schema — intentionally no EF FK
|
||||
/// (cross-schema references are by Guid only).
|
||||
///
|
||||
/// Multiple copies of the same CardDefinitionId may exist per account;
|
||||
/// each row is a distinct, individually tradeable instance.
|
||||
/// </summary>
|
||||
public sealed class PlayerCard
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Owning player. Cross-schema: no EF FK to identity.accounts.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
/// <summary>Template definition. Cross-schema: no EF FK to catalog.card_definitions.</summary>
|
||||
public Guid CardDefinitionId { get; set; }
|
||||
|
||||
public DateTimeOffset AcquiredAt { get; set; }
|
||||
|
||||
/// <summary>Foil/premium visual variant of the card art.</summary>
|
||||
public bool IsFoil { get; set; }
|
||||
|
||||
/// <summary>Sequential print number for limited/numbered cards. Null = unlimited.</summary>
|
||||
public int? SerialNumber { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace SOR.Database.Entities.Identity;
|
||||
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Extends ASP.NET Core Identity's IdentityUser with SOR-specific profile fields.
|
||||
///
|
||||
/// Identity manages: email, password hash, lockout, two-factor, external logins.
|
||||
/// We add: display name (in-game handle), avatar CDN URL, audit timestamps.
|
||||
///
|
||||
/// Ban handling uses Identity's built-in LockoutEnd + LockoutEnabled — no
|
||||
/// separate ban table needed for basic bans. A separate audit log of ban
|
||||
/// actions can be added later.
|
||||
/// </summary>
|
||||
public sealed class Account : IdentityUser<Guid>
|
||||
{
|
||||
/// <summary>Publicly visible in-game display name (not the login email).</summary>
|
||||
public string? DisplayName { get; set; }
|
||||
|
||||
/// <summary>CDN URL to the player's avatar image.</summary>
|
||||
public string? AvatarCdnUrl { get; set; }
|
||||
|
||||
/// <summary>UTC time the account was first created.</summary>
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
/// <summary>UTC time of the most recent successful login.</summary>
|
||||
public DateTimeOffset? LastLoginAt { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace SOR.Database.Entities.Identity;
|
||||
|
||||
/// <summary>
|
||||
/// Tracks an issued session token so it can be explicitly revoked
|
||||
/// (logout, password change, ban) before it naturally expires.
|
||||
///
|
||||
/// The raw token is never stored — only its SHA-256 hash is kept so
|
||||
/// that a stolen database row cannot be replayed.
|
||||
///
|
||||
/// The Gateway validates tokens by hashing the incoming token and
|
||||
/// looking it up here, checking RevokedAt == null and ExpiresAt > now.
|
||||
/// </summary>
|
||||
public sealed class AccountSession
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
|
||||
/// <summary>Owner of this session. No FK to preserve cross-schema flexibility.</summary>
|
||||
public Guid AccountId { get; set; }
|
||||
|
||||
/// <summary>SHA-256 hex digest of the raw session token.</summary>
|
||||
public string TokenHash { get; set; } = string.Empty;
|
||||
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
public DateTimeOffset ExpiresAt { get; set; }
|
||||
|
||||
/// <summary>Set when the session is explicitly invalidated (logout, ban, password change).</summary>
|
||||
public DateTimeOffset? RevokedAt { get; set; }
|
||||
|
||||
public string? IpAddress { get; set; }
|
||||
public string? UserAgent { get; set; }
|
||||
|
||||
/// <summary>Optional opaque device identifier supplied by the client.</summary>
|
||||
public string? DeviceId { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
/// <summary>
|
||||
/// All valid card/tile affinity values.
|
||||
///
|
||||
/// Basic affinities (the six primaries): Void, Aether, Lake, Hill, Forest, Field.
|
||||
/// Non-basic affinities are combinations of two basics via the tile slot system
|
||||
/// (Base1 + Base2). See affinity.md for full combination rules.
|
||||
///
|
||||
/// Cards may only carry basic and standard non-basic affinities.
|
||||
/// Gateway and UnstableAether affinities are tile-only — they cannot appear on cards.
|
||||
/// </summary>
|
||||
public enum Affinity
|
||||
{
|
||||
// ── Basic ──────────────────────────────────────────────────────────────
|
||||
Void,
|
||||
Aether,
|
||||
Lake,
|
||||
Hill,
|
||||
Forest,
|
||||
Field,
|
||||
|
||||
// ── Standard non-basic (two-basic combinations) ───────────────────────
|
||||
Ocean, // Lake + Lake
|
||||
Island, // Lake + Hill
|
||||
Marsh, // Lake + Forest
|
||||
Swamp, // Lake + Field
|
||||
Mountain, // Hill + Hill
|
||||
Steppe, // Hill + Forest
|
||||
Fort, // Hill + Field
|
||||
Plains, // Forest + Field
|
||||
Grove, // Forest + Forest
|
||||
Jungle, // Field + Field
|
||||
|
||||
// ── Aether combinations ───────────────────────────────────────────────
|
||||
UnstableAether, // Aether + any non-Aether (tile-only, cannot appear on cards)
|
||||
PerfectAether, // Aether + Aether
|
||||
|
||||
// ── Void combinations ─────────────────────────────────────────────────
|
||||
PureVoid, // Void + Void
|
||||
|
||||
// ── Gateway (Void + one basic, tile-only) ─────────────────────────────
|
||||
GatewayLake,
|
||||
GatewayHill,
|
||||
GatewayForest,
|
||||
GatewayField,
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
public enum BazaarListingStatus
|
||||
{
|
||||
Active,
|
||||
Sold,
|
||||
Cancelled,
|
||||
Expired,
|
||||
}
|
||||
|
||||
public enum BazaarListingType
|
||||
{
|
||||
/// <summary>Buy-it-now at a fixed price.</summary>
|
||||
Fixed,
|
||||
/// <summary>Timed auction — highest bid wins.</summary>
|
||||
Auction,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// In-game currency types.
|
||||
/// Gold: earned through gameplay, tradeable.
|
||||
/// Premium: purchased with real money, non-tradeable.
|
||||
/// </summary>
|
||||
public enum BazaarCurrency
|
||||
{
|
||||
Gold,
|
||||
Premium,
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
public enum CardType
|
||||
{
|
||||
ArchSpirit,
|
||||
Spirit,
|
||||
Repentance,
|
||||
Terramorpha,
|
||||
Ruin,
|
||||
Instinct,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How a unit's attack is resolved on the battlefield.
|
||||
/// The exact attack resolution rules are defined in gameplay.md.
|
||||
/// </summary>
|
||||
public enum AttackType
|
||||
{
|
||||
Melee,
|
||||
Ranged,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Governs how a unit traverses the battlefield.
|
||||
/// Walk: blocked by any unit.
|
||||
/// Flight: blocked by other Flight units only.
|
||||
/// Jump: unblocked, min/max tile range, costs 1 MP per landing tile.
|
||||
/// Teleport: unblocked, min/max range, requires line-of-sight, costs 1 MP per tile.
|
||||
/// </summary>
|
||||
public enum MovementType
|
||||
{
|
||||
Walk,
|
||||
Flight,
|
||||
Jump,
|
||||
Teleport,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// How many affinity tiles a Terramorpha card affects when channeled.
|
||||
/// Mono = 1 tile, Di = 2 adjacent tiles, Tri = 3 adjacent tiles.
|
||||
/// </summary>
|
||||
public enum TerramorphaMode
|
||||
{
|
||||
Mono,
|
||||
Di,
|
||||
Tri,
|
||||
}
|
||||
|
||||
public enum CardRarity
|
||||
{
|
||||
Common,
|
||||
Uncommon,
|
||||
Rare,
|
||||
Epic,
|
||||
Legendary,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Discriminates the type of CDN asset linked to a card.
|
||||
/// Art2D: flat card illustration shown in hand/collection views.
|
||||
/// Model3D: glTF/GLB model rendered on the battlefield.
|
||||
/// </summary>
|
||||
public enum CardAssetType
|
||||
{
|
||||
Art2D,
|
||||
Model3D,
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace SOR.Database.Enums;
|
||||
|
||||
public enum ChatChannelType
|
||||
{
|
||||
/// <summary>Server-wide public chat.</summary>
|
||||
Global,
|
||||
/// <summary>Private channel for an active match.</summary>
|
||||
Match,
|
||||
/// <summary>Direct message between two accounts.</summary>
|
||||
Direct,
|
||||
/// <summary>Guild/clan channel.</summary>
|
||||
Guild,
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<AssemblyName>SOR.Database</AssemblyName>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Identity types live in Microsoft.AspNetCore.App -->
|
||||
<FrameworkReference Include="Microsoft.AspNetCore.App" />
|
||||
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" />
|
||||
<!-- Design-time only: enables 'dotnet ef migrations add' -->
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,74 @@
|
||||
namespace SOR.Database;
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SOR.Database.Contexts;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods to register each DbContext independently.
|
||||
/// Each service only calls the extension(s) it needs.
|
||||
///
|
||||
/// All contexts fall back to "Default" if a context-specific connection string
|
||||
/// is absent, so a single connection string works during local development
|
||||
/// while production can split contexts across servers by overriding individual keys.
|
||||
///
|
||||
/// Connection string key precedence (highest to lowest):
|
||||
/// ConnectionStrings:{ContextName} → ConnectionStrings:Default
|
||||
/// </summary>
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
public static IServiceCollection AddIdentityDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<SorIdentityDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Identity")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCatalogDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<CatalogDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Catalog")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCollectionDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<CollectionDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Collection")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddBazaarDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<BazaarDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Bazaar")));
|
||||
return services;
|
||||
}
|
||||
|
||||
public static IServiceCollection AddChatDatabase(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<ChatDbContext>(opts =>
|
||||
opts.UseNpgsql(Resolve(configuration, "Chat")));
|
||||
return services;
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static string Resolve(IConfiguration configuration, string contextName)
|
||||
=> configuration.GetConnectionString(contextName)
|
||||
?? configuration.GetConnectionString("Default")
|
||||
?? throw new InvalidOperationException(
|
||||
$"Missing connection string: '{contextName}' or 'Default'. " +
|
||||
"Add it to appsettings.json or environment variables.");
|
||||
}
|
||||
Reference in New Issue
Block a user