Files
sor/Server/src/SOR.Collection/CollectionMessages.cs
T
0198aec9e5 Add collection service — deck management + card inventory
SOR.Collection project (new):
- 8 message handlers over WebSocket: get_cards, get_decks, get_deck,
  create_deck, rename_deck, delete_deck, add_card, remove_card
- Deck construction rules (DeckRules.cs): min 20 / max 40 cards,
  max 4 copies per definition, max 20 decks per player
- add_card validates ownership (player must own enough physical copies),
  copy limit, deck size limit, and rejects ArchSpirits from the card list
- RefreshValidityAsync recalculates Deck.IsValid after every mutation
- Cross-context lookups (CollectionDbContext + CatalogDbContext) with
  batch queries — never N+1

Admin portal pages (new):
- /collection — overview stats (total cards, total decks, valid decks,
  unique players) + account ID lookup
- /collection/player/{accountId} — full player collection viewer:
  paginated card grid with name/type/affinity/rarity/foil/serial filters,
  deck list with expanded card tables, Grant Card modal (search + foil
  toggle, grants 1–100 copies), revoke individual card instances

Wiring:
- SOR.slnx + SOR.Host.csproj: added SOR.Collection project reference
- Program.cs: uncommented collection service registration
- NavMenu: added Collection item

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>
2026-02-25 12:28:17 -05:00

103 lines
3.4 KiB
C#

namespace SOR.Collection;
// ── Request types (client → server) ──────────────────────────────────────────
/// <summary>
/// Paginated list of all cards the authenticated player owns.
/// NameFilter: case-insensitive substring match on card name (optional).
/// CardTypeFilter / AffinityFilter: exact enum name match (optional).
/// </summary>
public sealed record GetCardsRequest(
int Page = 1,
int PageSize = 50,
string? NameFilter = null,
string? CardTypeFilter = null,
string? AffinityFilter = null);
/// <summary>Returns all decks for the authenticated player (summaries only).</summary>
public sealed record GetDecksRequest; // no fields — identity from connection
/// <summary>Returns one deck with its full card list and owned-count per card.</summary>
public sealed record GetDeckRequest(Guid DeckId);
/// <summary>
/// Creates a new deck.
/// ArchSpiritCardDefinitionId must be an ArchSpirit card the player owns.
/// </summary>
public sealed record CreateDeckRequest(string Name, Guid ArchSpiritCardDefinitionId);
/// <summary>Renames an existing deck the player owns.</summary>
public sealed record RenameDeckRequest(Guid DeckId, string Name);
/// <summary>Permanently deletes a deck and all its DeckCard rows.</summary>
public sealed record DeleteDeckRequest(Guid DeckId);
/// <summary>
/// Adds (or increases the quantity of) a card definition to a deck.
/// Quantity is the number of copies to add (default 1).
/// Fails if the player does not own enough copies or deck/copy limits are exceeded.
/// </summary>
public sealed record AddCardRequest(Guid DeckId, Guid CardDefinitionId, int Quantity = 1);
/// <summary>
/// Removes copies of a card definition from a deck.
/// Quantity null → remove all copies of that definition.
/// </summary>
public sealed record RemoveCardRequest(Guid DeckId, Guid CardDefinitionId, int? Quantity = null);
// ── Response / DTO types (server → client) ────────────────────────────────────
public sealed record GetCardsResponse(
IEnumerable<PlayerCardDto> Cards,
int TotalCount,
int Page,
int PageSize);
public sealed record PlayerCardDto(
Guid PlayerCardId,
Guid CardDefinitionId,
string Name,
string CardType,
string Affinity,
string Rarity,
bool IsFoil,
int? SerialNumber,
DateTimeOffset AcquiredAt,
string? ArtUrl);
public sealed record GetDecksResponse(IEnumerable<DeckSummaryDto> Decks);
public sealed record DeckSummaryDto(
Guid Id,
string Name,
Guid ArchSpiritCardDefinitionId,
string? ArchSpiritName,
int CardCount,
bool IsValid,
DateTimeOffset CreatedAt,
DateTimeOffset UpdatedAt);
public sealed record GetDeckResponse(DeckDetailDto? Deck);
public sealed record DeckDetailDto(
Guid Id,
string Name,
Guid ArchSpiritCardDefinitionId,
string? ArchSpiritName,
bool IsValid,
DateTimeOffset CreatedAt,
DateTimeOffset UpdatedAt,
IEnumerable<DeckCardDto> Cards);
public sealed record DeckCardDto(
Guid CardDefinitionId,
string Name,
string CardType,
string Affinity,
string Rarity,
string? ArtUrl,
int Quantity,
int OwnedCount);
public sealed record DeckMutationResponse(DeckSummaryDto Deck);