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,238 @@
@page "/bazaar/cosmetics/new"
@page "/bazaar/cosmetics/{Id:guid}"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Entities.Bazaar
@using SOR.Database.Enums
@inject BazaarDbContext Db
@inject CatalogDbContext CatalogDb
@inject SOR.Cdn.ICdnClient Cdn
@inject NavigationManager Nav
<PageTitle>@(IsNew ? "New Cosmetic" : "Edit Cosmetic") – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="mb-0">@(IsNew ? "New Cosmetic" : "Edit Cosmetic")</h1>
<a href="/bazaar/cosmetics" class="btn btn-outline-secondary btn-sm">
<i class="bi bi-arrow-left me-1"></i>Back
</a>
</div>
@if (_cosmetic is null)
{
<p class="text-muted">Loading…</p>
}
else
{
<div class="row g-4">
<div class="col-md-7">
<div class="card shadow-sm">
<div class="card-header fw-medium">Details</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label fw-medium">Name</label>
<input @bind="_cosmetic.Name" class="form-control" placeholder="e.g. Ember Card Back" />
</div>
<div class="mb-3">
<label class="form-label fw-medium">Description</label>
<textarea @bind="_cosmetic.Description" class="form-control" rows="2"
placeholder="Optional description shown in the store." />
</div>
<div class="row g-3 mb-3">
<div class="col-md-6">
<label class="form-label fw-medium">Type</label>
<select @bind="_cosmeticTypeStr" class="form-select">
@foreach (var t in Enum.GetNames<CosmeticType>())
{
<option value="@t">@t</option>
}
</select>
</div>
@if (_cosmetic.CosmeticType != CosmeticType.CardBack)
{
<div class="col-md-6">
<label class="form-label fw-medium">Card (optional)</label>
<input @bind="_cardDefinitionIdStr"
class="form-control font-monospace"
placeholder="Card Definition GUID" />
</div>
}
</div>
<div class="row g-3 mb-3">
<div class="col-md-6">
<label class="form-label fw-medium">Origin Point Price</label>
<input @bind="_cosmetic.OriginPointPrice" type="number"
class="form-control" min="0" />
</div>
<div class="col-md-6">
<label class="form-label fw-medium">USD Price (optional)</label>
<input @bind="_cosmetic.UsdPrice" type="number"
class="form-control" step="0.01" min="0"
placeholder="Leave blank for OP-only" />
</div>
</div>
<div class="form-check mb-3">
<input @bind="_cosmetic.IsActive" type="checkbox"
class="form-check-input" id="chkActive" />
<label class="form-check-label fw-medium" for="chkActive">Active</label>
</div>
</div>
</div>
</div>
<div class="col-md-5">
<!-- Preview Image -->
<div class="card shadow-sm mb-3">
<div class="card-header fw-medium">Preview Image (thumbnail)</div>
<div class="card-body">
@if (!string.IsNullOrEmpty(_cosmetic.PreviewImageCdnUrl))
{
<img src="@_cosmetic.PreviewImageCdnUrl"
class="img-fluid rounded mb-2"
alt="Preview" style="max-height:120px" />
}
<input @bind="_cosmetic.PreviewImageCdnUrl"
class="form-control form-control-sm mb-2"
placeholder="https://cdn.sor.gg/…" />
<label class="btn btn-sm btn-outline-primary @(_uploadingPreview ? "disabled" : "")">
@if (_uploadingPreview) { <span class="spinner-border spinner-border-sm"></span> }
else { <i class="bi bi-upload"></i> }
<span class="ms-1">Upload</span>
<InputFile style="display:none" accept="image/*"
OnChange="UploadPreviewAsync" />
</label>
</div>
</div>
<!-- Asset -->
<div class="card shadow-sm">
<div class="card-header fw-medium">Asset URL (art / model)</div>
<div class="card-body">
<input @bind="_cosmetic.AssetCdnUrl"
class="form-control form-control-sm mb-2"
placeholder="https://cdn.sor.gg/…" />
<label class="btn btn-sm btn-outline-primary @(_uploadingAsset ? "disabled" : "")">
@if (_uploadingAsset) { <span class="spinner-border spinner-border-sm"></span> }
else { <i class="bi bi-upload"></i> }
<span class="ms-1">Upload</span>
<InputFile style="display:none"
accept="image/*,.glb,.gltf,.fbx"
OnChange="UploadAssetAsync" />
</label>
</div>
</div>
</div>
</div>
@if (!string.IsNullOrEmpty(_error))
{
<div class="alert alert-danger mt-3">@_error</div>
}
<div class="mt-4 d-flex gap-2">
<button class="btn btn-primary" @onclick="SaveAsync" disabled="@_saving">
@if (_saving) { <span class="spinner-border spinner-border-sm me-1"></span> }
Save
</button>
@if (!IsNew)
{
<button class="btn btn-outline-danger" @onclick="DeleteAsync">
<i class="bi bi-trash me-1"></i>Delete
</button>
}
</div>
}
@code {
[Parameter] public Guid? Id { get; set; }
private bool IsNew => !Id.HasValue;
private Cosmetic? _cosmetic;
private string _cosmeticTypeStr = nameof(CosmeticType.CardBack);
private string _cardDefinitionIdStr = string.Empty;
private bool _saving, _uploadingPreview, _uploadingAsset;
private string? _error;
protected override async Task OnInitializedAsync()
{
if (IsNew)
{
_cosmetic = new Cosmetic { CreatedAt = DateTimeOffset.UtcNow, UpdatedAt = DateTimeOffset.UtcNow };
}
else
{
_cosmetic = await Db.Cosmetics.FirstOrDefaultAsync(c => c.Id == Id!.Value);
if (_cosmetic is null) { Nav.NavigateTo("/bazaar/cosmetics"); return; }
_cosmeticTypeStr = _cosmetic.CosmeticType.ToString();
_cardDefinitionIdStr = _cosmetic.CardDefinitionId?.ToString() ?? string.Empty;
}
}
private async Task UploadPreviewAsync(InputFileChangeEventArgs e)
{
_uploadingPreview = true;
_error = null;
try
{
await using var stream = e.File.OpenReadStream(maxAllowedSize: 10 * 1024 * 1024);
var result = await Cdn.UploadAsync("cosmetics/previews", e.File.Name, e.File.ContentType, stream);
_cosmetic!.PreviewImageCdnUrl = result.PublicUrl ?? string.Empty;
}
catch (Exception ex) { _error = $"Upload failed: {ex.Message}"; }
finally { _uploadingPreview = false; }
}
private async Task UploadAssetAsync(InputFileChangeEventArgs e)
{
_uploadingAsset = true;
_error = null;
try
{
await using var stream = e.File.OpenReadStream(maxAllowedSize: 50 * 1024 * 1024);
var result = await Cdn.UploadAsync("cosmetics/assets", e.File.Name, e.File.ContentType, stream);
_cosmetic!.AssetCdnUrl = result.PublicUrl ?? string.Empty;
}
catch (Exception ex) { _error = $"Upload failed: {ex.Message}"; }
finally { _uploadingAsset = false; }
}
private async Task SaveAsync()
{
_error = null;
if (string.IsNullOrWhiteSpace(_cosmetic!.Name))
{ _error = "Name is required."; return; }
if (string.IsNullOrWhiteSpace(_cosmetic.AssetCdnUrl))
{ _error = "Asset URL is required."; return; }
if (!Enum.TryParse<CosmeticType>(_cosmeticTypeStr, out var t))
{ _error = "Invalid cosmetic type."; return; }
_cosmetic.CosmeticType = t;
_cosmetic.CardDefinitionId = string.IsNullOrWhiteSpace(_cardDefinitionIdStr) ? null
: Guid.TryParse(_cardDefinitionIdStr, out var g) ? g : null;
_saving = true;
try
{
_cosmetic.UpdatedAt = DateTimeOffset.UtcNow;
if (IsNew) Db.Cosmetics.Add(_cosmetic);
await Db.SaveChangesAsync();
Nav.NavigateTo("/bazaar/cosmetics");
}
catch (Exception ex) { _error = $"Save failed: {ex.Message}"; }
finally { _saving = false; }
}
private async Task DeleteAsync()
{
Db.Cosmetics.Remove(_cosmetic!);
await Db.SaveChangesAsync();
Nav.NavigateTo("/bazaar/cosmetics");
}
}
@@ -0,0 +1,121 @@
@page "/bazaar/cosmetics"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Enums
@inject BazaarDbContext Db
@inject NavigationManager Nav
<PageTitle>Cosmetics – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="mb-0">Cosmetics</h1>
<a href="/bazaar/cosmetics/new" class="btn btn-primary">
<i class="bi bi-plus-lg me-1"></i>New Cosmetic
</a>
</div>
@if (_loading)
{
<p class="text-muted">Loading…</p>
}
else
{
<div class="card shadow-sm">
<div class="card-body p-0">
<table class="table table-sm table-hover mb-0">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Type</th>
<th>Card</th>
<th class="text-end">OP Price</th>
<th class="text-end">USD</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var c in _cosmetics)
{
<tr>
<td class="fw-medium">@c.Name</td>
<td>
<span class="badge @TypeBadge(c.Type)">@c.Type</span>
</td>
<td class="text-muted small">@(c.CardName ?? "—")</td>
<td class="text-end">@c.OriginPointPrice.ToString("N0")</td>
<td class="text-end text-muted small">
@(c.UsdPrice.HasValue ? $"${c.UsdPrice:F2}" : "—")
</td>
<td>
@if (c.IsActive)
{
<span class="badge bg-success">Active</span>
}
else
{
<span class="badge bg-secondary">Inactive</span>
}
</td>
<td>
<a href="/bazaar/cosmetics/@c.Id"
class="btn btn-sm btn-outline-secondary">
<i class="bi bi-pencil"></i>
</a>
</td>
</tr>
}
@if (!_cosmetics.Any())
{
<tr>
<td colspan="7" class="text-muted text-center py-3">
No cosmetics yet. <a href="/bazaar/cosmetics/new">Create one.</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
@code {
private bool _loading = true;
private record CosmeticRow(
Guid Id,
string Name,
string Type,
string? CardName,
int OriginPointPrice,
decimal? UsdPrice,
bool IsActive);
private List<CosmeticRow> _cosmetics = new();
protected override async Task OnInitializedAsync()
{
_cosmetics = await Db.Cosmetics
.OrderBy(c => c.CosmeticType)
.ThenBy(c => c.Name)
.Select(c => new CosmeticRow(
c.Id,
c.Name,
c.CosmeticType.ToString(),
null,
c.OriginPointPrice,
c.UsdPrice,
c.IsActive))
.ToListAsync();
_loading = false;
}
private static string TypeBadge(string type) => type switch
{
nameof(CosmeticType.CardBack) => "bg-info text-dark",
nameof(CosmeticType.AlternateCardArt) => "bg-primary",
nameof(CosmeticType.AlternateCardModel) => "bg-warning text-dark",
_ => "bg-secondary",
};
}
@@ -0,0 +1,277 @@
@page "/bazaar/purchases"
@attribute [Authorize(Roles = "Admin,SuperAdmin")]
@using Microsoft.EntityFrameworkCore
@using SOR.Database.Contexts
@using SOR.Database.Enums
@inject BazaarDbContext Db
<PageTitle>Purchase Records – SOR Admin</PageTitle>
<div class="d-flex justify-content-between align-items-center mb-4">
<h1 class="mb-0">Purchase Records</h1>
<button class="btn btn-outline-secondary btn-sm" @onclick="LoadAsync">
<i class="bi bi-arrow-clockwise me-1"></i>Refresh
</button>
</div>
<!-- Filters -->
<div class="card shadow-sm mb-4">
<div class="card-body">
<div class="row g-3">
<div class="col-md-3">
<label class="form-label small fw-medium">Account ID</label>
<input @bind="_filterAccountId" class="form-control form-control-sm font-monospace"
placeholder="GUID" />
</div>
<div class="col-md-3">
<label class="form-label small fw-medium">Product Type</label>
<select @bind="_filterProductType" class="form-select form-select-sm">
<option value="">All</option>
@foreach (var t in Enum.GetNames<PurchaseProductType>())
{
<option value="@t">@t</option>
}
</select>
</div>
<div class="col-md-2">
<label class="form-label small fw-medium">From</label>
<input @bind="_filterFrom" type="date" class="form-control form-control-sm" />
</div>
<div class="col-md-2">
<label class="form-label small fw-medium">To</label>
<input @bind="_filterTo" type="date" class="form-control form-control-sm" />
</div>
<div class="col-md-2 d-flex align-items-end">
<button class="btn btn-primary btn-sm w-100" @onclick="LoadAsync">
<i class="bi bi-search me-1"></i>Search
</button>
</div>
</div>
</div>
</div>
@if (_loading)
{
<p class="text-muted">Loading…</p>
}
else
{
<div class="card shadow-sm">
<div class="card-header fw-medium d-flex justify-content-between">
<span>Results</span>
<span class="badge bg-secondary">@_total records</span>
</div>
<div class="card-body p-0">
<table class="table table-sm table-hover mb-0">
<thead class="table-light">
<tr>
<th>Date</th>
<th>Account</th>
<th>Type</th>
<th>Product ID</th>
<th class="text-end">OP Spent</th>
<th class="text-end">USD</th>
<th class="text-end">Qty</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach (var r in _records)
{
<tr>
<td class="text-muted small">@r.PurchasedAt.ToString("yyyy-MM-dd HH:mm")</td>
<td class="font-monospace small">@r.AccountId.ToString()[..8]…</td>
<td><span class="badge @TypeBadge(r.ProductType)">@r.ProductType</span></td>
<td class="font-monospace small text-muted">
@(r.ProductId.HasValue ? r.ProductId.Value.ToString()[..8] + "…" : "—")
</td>
<td class="text-end">@r.OriginPointsSpent.ToString("N0")</td>
<td class="text-end text-muted small">
@(r.UsdSpent.HasValue ? $"${r.UsdSpent:F2}" : "—")
</td>
<td class="text-end">@r.QuantityGranted</td>
<td>
@if (r.ProductType == PurchaseProductType.BoosterPack.ToString() && r.HasGrants)
{
<button class="btn btn-sm btn-outline-secondary"
@onclick="() => ToggleGrants(r.Id)">
<i class="bi bi-card-list"></i>
</button>
}
</td>
</tr>
@if (_expandedGrants.Contains(r.Id))
{
<tr>
<td colspan="8" class="bg-light p-2">
<div class="small fw-medium mb-1">Cards Opened:</div>
@if (_grantsCache.TryGetValue(r.Id, out var grants))
{
<div class="d-flex flex-wrap gap-2">
@foreach (var g in grants)
{
<span class="badge @RarityBadge(g.Rarity)">
@g.CardName
@if (g.IsFoil) { <span class="ms-1">✨</span> }
</span>
}
</div>
}
else
{
<span class="text-muted">Loading…</span>
}
</td>
</tr>
}
}
@if (!_records.Any())
{
<tr>
<td colspan="8" class="text-muted text-center py-3">No records found.</td>
</tr>
}
</tbody>
</table>
</div>
</div>
<!-- Pagination -->
@if (_totalPages > 1)
{
<div class="d-flex justify-content-center gap-2 mt-3">
<button class="btn btn-sm btn-outline-secondary"
disabled="@(_page <= 1)"
@onclick="() => ChangePage(_page - 1)">
<i class="bi bi-chevron-left"></i>
</button>
<span class="btn btn-sm disabled">@_page / @_totalPages</span>
<button class="btn btn-sm btn-outline-secondary"
disabled="@(_page >= _totalPages)"
@onclick="() => ChangePage(_page + 1)">
<i class="bi bi-chevron-right"></i>
</button>
</div>
}
}
@code {
private bool _loading = true;
private int _page = 1, _totalPages = 1, _total;
private const int PageSize = 50;
private string _filterAccountId = string.Empty;
private string _filterProductType = string.Empty;
private DateOnly? _filterFrom, _filterTo;
private record PurchaseRow(
Guid Id,
DateTimeOffset PurchasedAt,
Guid AccountId,
string ProductType,
Guid? ProductId,
int OriginPointsSpent,
decimal? UsdSpent,
int QuantityGranted,
bool HasGrants);
private record GrantRow(string CardName, string Rarity, bool IsFoil);
private List<PurchaseRow> _records = new();
private HashSet<Guid> _expandedGrants = new();
private Dictionary<Guid, List<GrantRow>> _grantsCache = new();
protected override async Task OnInitializedAsync() => await LoadAsync();
private async Task LoadAsync()
{
_loading = true;
_expandedGrants.Clear();
var q = Db.PurchaseRecords.AsQueryable();
if (Guid.TryParse(_filterAccountId, out var accId))
q = q.Where(r => r.AccountId == accId);
if (!string.IsNullOrEmpty(_filterProductType) &&
Enum.TryParse<PurchaseProductType>(_filterProductType, out var pt))
q = q.Where(r => r.ProductType == pt);
if (_filterFrom.HasValue)
{
var from = new DateTimeOffset(_filterFrom.Value.ToDateTime(TimeOnly.MinValue), TimeSpan.Zero);
q = q.Where(r => r.PurchasedAt >= from);
}
if (_filterTo.HasValue)
{
var to = new DateTimeOffset(_filterTo.Value.ToDateTime(TimeOnly.MaxValue), TimeSpan.Zero);
q = q.Where(r => r.PurchasedAt <= to);
}
_total = await q.CountAsync();
_totalPages = Math.Max(1, (int)Math.Ceiling(_total / (double)PageSize));
_page = Math.Clamp(_page, 1, _totalPages);
_records = await q
.OrderByDescending(r => r.PurchasedAt)
.Skip((_page - 1) * PageSize)
.Take(PageSize)
.Select(r => new PurchaseRow(
r.Id,
r.PurchasedAt,
r.AccountId,
r.ProductType.ToString(),
r.ProductId,
r.OriginPointsSpent,
r.UsdSpent,
r.QuantityGranted,
r.CardGrants.Any()))
.ToListAsync();
_loading = false;
}
private async Task ToggleGrants(Guid id)
{
if (_expandedGrants.Contains(id))
{
_expandedGrants.Remove(id);
return;
}
_expandedGrants.Add(id);
if (!_grantsCache.ContainsKey(id))
{
var grants = await Db.BoosterPackCardGrants
.Where(g => g.PurchaseRecordId == id)
.OrderBy(g => g.Rarity)
.ThenBy(g => g.CardName)
.Select(g => new GrantRow(g.CardName, g.Rarity, g.IsFoil))
.ToListAsync();
_grantsCache[id] = grants;
}
}
private async Task ChangePage(int p)
{
_page = p;
await LoadAsync();
}
private static string TypeBadge(string type) => type switch
{
nameof(PurchaseProductType.BoosterPack) => "bg-primary",
nameof(PurchaseProductType.PrebuiltDeck) => "bg-success",
nameof(PurchaseProductType.Cosmetic) => "bg-warning text-dark",
nameof(PurchaseProductType.OriginPointTopUp) => "bg-info text-dark",
_ => "bg-secondary",
};
private static string RarityBadge(string rarity) => rarity switch
{
"Legendary" => "bg-warning text-dark",
"Epic" => "bg-purple",
"Rare" => "bg-primary",
"Uncommon" => "bg-success",
_ => "bg-secondary",
};
}