Add SOR.Bazaar service — store, P2P marketplace, auction house, cosmetics

New project: SOR.Bazaar (12 message handlers)
  Store:       get_store, buy_booster_pack, buy_prebuilt_deck, buy_cosmetic, get_my_balance
  Marketplace: get_listings, get_my_listings, list_card, cancel_listing,
               buy_listing (shared-tx atomicity), place_bid (shared-tx + refund),
               get_transactions

New DB entities:
  BazaarDb:    Cosmetic, PurchaseRecord, BoosterPackCardGrant, AuctionBid
  CollectionDb: PlayerCosmetic
  IdentityDb:  Account.OriginPoints

BoosterPack gets CardSetId for set-scoped card pool draws.
BazaarEnums: PurchaseProductType, CosmeticType.

3 EF migrations applied to pg-forge-01:
  AddOriginPoints, AddBazaarCosmetics, AddPlayerCosmetics

Admin pages: CosmeticsPage, CosmeticEditor, PurchaseRecordsPage (with
  expandable booster pack card grant rows), NavMenu Bazaar submenu updates.

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 19:02:59 -05:00
co-authored by Claude Happy
parent 2cac55cbd9
commit 348c37b9b5
42 changed files with 4127 additions and 10 deletions
@@ -0,0 +1,36 @@
namespace SOR.Database.Entities.Bazaar;
using SOR.Database.Enums;
/// <summary>
/// A bid placed on an Auction-type BazaarListing.
///
/// At most one bid per listing has IsWinning = true (the current highest bid).
/// When a new higher bid arrives, the previous winning bid is set to IsWinning = false
/// and the bidder's Origin Points are refunded, atomically within the same transaction.
///
/// When the listing's ExpiresAt passes, the winning bidder receives the card and the
/// seller receives the winning bid amount (handled by the auction-resolution job).
/// </summary>
public sealed class AuctionBid
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid ListingId { get; set; }
/// <summary>Cross-schema: the account that placed this bid.</summary>
public Guid BidderAccountId { get; set; }
public decimal Amount { get; set; }
public BazaarCurrency Currency { get; set; }
public DateTimeOffset PlacedAt { get; set; }
/// <summary>
/// True only for the current highest bid on this listing.
/// Previous winning bids are set to false when outbid.
/// </summary>
public bool IsWinning { get; set; }
public BazaarListing Listing { get; set; } = null!;
}
@@ -42,6 +42,12 @@ public sealed class BoosterPack
/// </summary>
public string? SlotsJson { get; set; }
/// <summary>
/// Cross-schema: restricts the card draw pool to cards belonging to this CardSet.
/// Null = draw from all published cards of matching rarity across the entire catalog.
/// </summary>
public Guid? CardSetId { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
@@ -0,0 +1,32 @@
namespace SOR.Database.Entities.Bazaar;
/// <summary>
/// Records a single card received when a player opens a booster pack.
/// One row per card drawn; linked to the parent PurchaseRecord.
///
/// CardDefinitionId, CardName, and Rarity are denormalized from the
/// catalog schema to make historical reporting self-contained — we never
/// want a report query to break because a card was renamed.
/// </summary>
public sealed class BoosterPackCardGrant
{
public Guid Id { get; set; } = Guid.NewGuid();
public Guid PurchaseRecordId { get; set; }
/// <summary>Cross-schema: the PlayerCard instance created in the collection schema.</summary>
public Guid PlayerCardId { get; set; }
/// <summary>Denormalized from CardDefinition for self-contained reporting.</summary>
public Guid CardDefinitionId { get; set; }
/// <summary>Denormalized card name at time of grant.</summary>
public string CardName { get; set; } = string.Empty;
/// <summary>Denormalized rarity string at time of grant.</summary>
public string Rarity { get; set; } = string.Empty;
public bool IsFoil { get; set; }
public PurchaseRecord PurchaseRecord { get; set; } = null!;
}
@@ -0,0 +1,49 @@
namespace SOR.Database.Entities.Bazaar;
using SOR.Database.Enums;
/// <summary>
/// A purchasable cosmetic item available in the bazaar store.
///
/// CardBack — global cosmetic; applies to all of the player's cards.
/// CardDefinitionId is null.
/// AlternateCardArt — replaces the 2D art asset for a specific card definition.
/// CardDefinitionId is set.
/// AlternateCardModel — replaces the 3D model asset for a specific card definition.
/// CardDefinitionId is set.
///
/// AssetCdnUrl points to the actual art file / model file.
/// PreviewImageCdnUrl is a smaller thumbnail used in store listings.
/// </summary>
public sealed class Cosmetic
{
public Guid Id { get; set; } = Guid.NewGuid();
public string Name { get; set; } = string.Empty;
public string? Description { get; set; }
public CosmeticType CosmeticType { get; set; }
/// <summary>
/// Cross-schema: links to a specific card definition for AlternateCardArt /
/// AlternateCardModel cosmetics. Null for CardBack (global cosmetics).
/// </summary>
public Guid? CardDefinitionId { get; set; }
/// <summary>Thumbnail shown in store listings.</summary>
public string? PreviewImageCdnUrl { get; set; }
/// <summary>The actual cosmetic asset (art file, model file, card back texture).</summary>
public string AssetCdnUrl { get; set; } = string.Empty;
/// <summary>Cost in origin points.</summary>
public int OriginPointPrice { get; set; }
/// <summary>Cost in USD. Null if not available for real-money purchase.</summary>
public decimal? UsdPrice { get; set; }
public bool IsActive { get; set; }
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
}
@@ -0,0 +1,49 @@
namespace SOR.Database.Entities.Bazaar;
using SOR.Database.Enums;
/// <summary>
/// Immutable record of every purchase made through the bazaar store.
/// Created for every BoosterPack open, PrebuiltDeck purchase, Cosmetic purchase,
/// and Origin Point top-up. Never updated or deleted.
///
/// For BoosterPack purchases, CardGrants lists the exact cards received.
/// </summary>
public sealed class PurchaseRecord
{
public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>Cross-schema: the account that made the purchase.</summary>
public Guid AccountId { get; set; }
public PurchaseProductType ProductType { get; set; }
/// <summary>
/// The product that was purchased (pack/deck/cosmetic ID).
/// Null for OriginPointTopUp purchases.
/// </summary>
public Guid? ProductId { get; set; }
/// <summary>
/// Origin points deducted from the account for this purchase.
/// Zero for USD-only purchases.
/// </summary>
public int OriginPointsSpent { get; set; }
/// <summary>
/// USD charged for this purchase.
/// Null for Origin Point purchases.
/// </summary>
public decimal? UsdSpent { get; set; }
/// <summary>
/// Number of cards opened (for BoosterPack) or Origin Points granted (for TopUp).
/// 1 for Deck and Cosmetic purchases.
/// </summary>
public int QuantityGranted { get; set; } = 1;
public DateTimeOffset PurchasedAt { get; set; }
/// <summary>Cards received from a booster pack opening. Empty for other product types.</summary>
public ICollection<BoosterPackCardGrant> CardGrants { get; set; } = new List<BoosterPackCardGrant>();
}
@@ -0,0 +1,21 @@
namespace SOR.Database.Entities.Collection;
/// <summary>
/// A cosmetic item owned by a player.
/// Created when a player purchases a cosmetic from the bazaar store.
///
/// CosmeticId is a cross-schema bare Guid referencing bazaar.cosmetics.
/// No EF FK — the collection schema is independent of the bazaar schema.
/// </summary>
public sealed class PlayerCosmetic
{
public Guid Id { get; set; } = Guid.NewGuid();
/// <summary>Cross-schema: the account that owns this cosmetic.</summary>
public Guid AccountId { get; set; }
/// <summary>Cross-schema: references bazaar.cosmetics.id.</summary>
public Guid CosmeticId { get; set; }
public DateTimeOffset AcquiredAt { get; set; }
}
@@ -31,4 +31,11 @@ public sealed class Account : IdentityUser<Guid>
/// Null means they have not yet chosen their starter deck.
/// </summary>
public DateTimeOffset? StarterDeckSelectedAt { get; set; }
/// <summary>
/// In-game earned currency balance (Origin Points / Gold).
/// Earned through gameplay; can also be purchased from the bazaar store.
/// Spent on booster packs, prebuilt decks, cosmetics, and P2P listings.
/// </summary>
public int OriginPoints { get; set; }
}