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:
@@ -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; }
|
||||
}
|
||||
Reference in New Issue
Block a user