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>
This commit is contained in:
dingo
2026-02-25 12:28:17 -05:00
co-authored by Claude Happy
parent 925b2b1b3b
commit 0198aec9e5
19 changed files with 1594 additions and 3 deletions
@@ -0,0 +1,36 @@
namespace SOR.Collection;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SOR.Collection.Handlers;
using SOR.Database;
using SOR.Networking.Abstractions.Messaging;
/// <summary>
/// Registers all collection service components into the DI container.
/// Called from SOR.Host/Program.cs when ENABLED_SERVICES includes "collection".
/// </summary>
public static class ServiceRegistration
{
public static IServiceCollection AddCollectionService(
this IServiceCollection services,
IConfiguration configuration)
{
// Database contexts the collection service needs.
services.AddCollectionDatabase(configuration);
services.AddCatalogDatabase(configuration);
// Message handlers — one per message type, Transient lifetime.
// MessageDispatcher collects all IMessageHandler registrations at startup.
services.AddTransient<IMessageHandler, CollectionGetCardsHandler>();
services.AddTransient<IMessageHandler, CollectionGetDecksHandler>();
services.AddTransient<IMessageHandler, CollectionGetDeckHandler>();
services.AddTransient<IMessageHandler, CollectionCreateDeckHandler>();
services.AddTransient<IMessageHandler, CollectionRenameDeckHandler>();
services.AddTransient<IMessageHandler, CollectionDeleteDeckHandler>();
services.AddTransient<IMessageHandler, CollectionAddCardHandler>();
services.AddTransient<IMessageHandler, CollectionRemoveCardHandler>();
return services;
}
}