feat(sleeve): shop catalog + /sleeve/{info,buy} endpoints

Schema: SleeveShopSeries -> SleeveShopProducts -> Rewards (owned).
Migration AddSleeveShop creates 3 tables with FK cascade.

Importer mirrors BuildDeck pattern: find-or-create per series/product,
rewards replaced wholesale on rerun (owned collection). 10 series,
270 products imported from seeds/sleeve-shop.json.

Controller:
- /sleeve/info returns wire-faithful dict-keyed shape
  ({sleeve_list: {<series_id>: {product_info: {<product_id>: ...}}}}).
  is_purchased_product derived from viewer.Sleeves.Contains(sleeve_id).
- /sleeve/buy: sales_type 0=free / 1=crystal / 2=rupy / 3=ticket(501).
  Validates series_product mismatch, currency, already-purchased.
  Currency debited with post-state-total reward_list entry; cosmetic
  grants dispatched through RewardGrantService.ApplyAsync (covers
  sleeve + emblem bundled grants per product).

476 tests pass (was 466; +10 sleeve tests).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-05-27 22:09:45 -04:00
parent 6a03ff1bf6
commit f237851e42
18 changed files with 10316 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,96 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace SVSim.Database.Migrations
{
/// <inheritdoc />
public partial class AddSleeveShop : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "SleeveShopSeries",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false),
IsNew = table.Column<bool>(type: "boolean", nullable: false),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SleeveShopSeries", x => x.Id);
});
migrationBuilder.CreateTable(
name: "SleeveShopProducts",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false),
SeriesId = table.Column<int>(type: "integer", nullable: false),
NameKey = table.Column<string>(type: "text", nullable: false),
PriceCrystal = table.Column<int>(type: "integer", nullable: true),
PriceRupy = table.Column<int>(type: "integer", nullable: true),
IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
DateCreated = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateUpdated = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SleeveShopProducts", x => x.Id);
table.ForeignKey(
name: "FK_SleeveShopProducts_SleeveShopSeries_SeriesId",
column: x => x.SeriesId,
principalTable: "SleeveShopSeries",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "SleeveShopProductRewardEntry",
columns: table => new
{
SleeveShopProductEntryId = table.Column<int>(type: "integer", nullable: false),
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OrderIndex = table.Column<int>(type: "integer", nullable: false),
RewardType = table.Column<int>(type: "integer", nullable: false),
RewardDetailId = table.Column<long>(type: "bigint", nullable: false),
RewardNumber = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SleeveShopProductRewardEntry", x => new { x.SleeveShopProductEntryId, x.Id });
table.ForeignKey(
name: "FK_SleeveShopProductRewardEntry_SleeveShopProducts_SleeveShopP~",
column: x => x.SleeveShopProductEntryId,
principalTable: "SleeveShopProducts",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_SleeveShopProducts_SeriesId",
table: "SleeveShopProducts",
column: "SeriesId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SleeveShopProductRewardEntry");
migrationBuilder.DropTable(
name: "SleeveShopProducts");
migrationBuilder.DropTable(
name: "SleeveShopSeries");
}
}
}

View File

@@ -1964,6 +1964,62 @@ namespace SVSim.Database.Migrations
b.ToTable("Sleeves");
});
modelBuilder.Entity("SVSim.Database.Models.SleeveShopProductEntry", b =>
{
b.Property<int>("Id")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateUpdated")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<string>("NameKey")
.IsRequired()
.HasColumnType("text");
b.Property<int?>("PriceCrystal")
.HasColumnType("integer");
b.Property<int?>("PriceRupy")
.HasColumnType("integer");
b.Property<int>("SeriesId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("SeriesId");
b.ToTable("SleeveShopProducts");
});
modelBuilder.Entity("SVSim.Database.Models.SleeveShopSeriesEntry", b =>
{
b.Property<int>("Id")
.HasColumnType("integer");
b.Property<DateTime>("DateCreated")
.HasColumnType("timestamp with time zone");
b.Property<DateTime?>("DateUpdated")
.HasColumnType("timestamp with time zone");
b.Property<bool>("IsEnabled")
.HasColumnType("boolean");
b.Property<bool>("IsNew")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("SleeveShopSeries");
});
modelBuilder.Entity("SVSim.Database.Models.SpecialDeckFormatEntry", b =>
{
b.Property<int>("Id")
@@ -2828,6 +2884,50 @@ namespace SVSim.Database.Migrations
b.Navigation("Sleeve");
});
modelBuilder.Entity("SVSim.Database.Models.SleeveShopProductEntry", b =>
{
b.HasOne("SVSim.Database.Models.SleeveShopSeriesEntry", "Series")
.WithMany("Products")
.HasForeignKey("SeriesId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.OwnsMany("SVSim.Database.Models.SleeveShopProductRewardEntry", "Rewards", b1 =>
{
b1.Property<int>("SleeveShopProductEntryId")
.HasColumnType("integer");
b1.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
b1.Property<int>("OrderIndex")
.HasColumnType("integer");
b1.Property<long>("RewardDetailId")
.HasColumnType("bigint");
b1.Property<int>("RewardNumber")
.HasColumnType("integer");
b1.Property<int>("RewardType")
.HasColumnType("integer");
b1.HasKey("SleeveShopProductEntryId", "Id");
b1.ToTable("SleeveShopProductRewardEntry");
b1.WithOwner()
.HasForeignKey("SleeveShopProductEntryId");
});
b.Navigation("Rewards");
b.Navigation("Series");
});
modelBuilder.Entity("SVSim.Database.Models.Viewer", b =>
{
b.OwnsMany("SVSim.Database.Models.OwnedCardEntry", "Cards", b1 =>
@@ -3259,6 +3359,11 @@ namespace SVSim.Database.Migrations
b.Navigation("Cards");
});
modelBuilder.Entity("SVSim.Database.Models.SleeveShopSeriesEntry", b =>
{
b.Navigation("Products");
});
modelBuilder.Entity("SVSim.Database.Models.Viewer", b =>
{
b.Navigation("Achievements");

View File

@@ -0,0 +1,32 @@
using SVSim.Database.Common;
namespace SVSim.Database.Models;
/// <summary>
/// One purchasable sleeve product. PK = wire product_id (e.g. 301901). FK SeriesId.
/// <para>
/// Both <see cref="PriceCrystal"/> and <see cref="PriceRupy"/> are nullable. At least one must be
/// populated for an enabled product (both zero = free, both null = invalid). Sleeves don't have
/// the two-tier intro/regular pricing that BuildDeck products use — one price per currency.
/// </para>
/// <para>
/// <see cref="Rewards"/> drives both the catalog display (in /sleeve/info) and the actual grant
/// list (in /sleeve/buy). The capture shows each sleeve product grants a sleeve (type=6) and an
/// emblem (type=7) — both faithful reward_detail_ids that exist in the cosmetic catalogs.
/// </para>
/// </summary>
public class SleeveShopProductEntry : BaseEntity<int>
{
public int SeriesId { get; set; }
/// <summary>Wire `name` field — SystemText key like "sleeve_138". Localised client-side.</summary>
public string NameKey { get; set; } = string.Empty;
public int? PriceCrystal { get; set; }
public int? PriceRupy { get; set; }
public bool IsEnabled { get; set; }
public List<SleeveShopProductRewardEntry> Rewards { get; set; } = new();
public SleeveShopSeriesEntry? Series { get; set; }
}

View File

@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
namespace SVSim.Database.Models;
/// <summary>
/// One per-buy reward attached to a sleeve product. Owned by <see cref="SleeveShopProductEntry"/>.
/// Wire shape: one entry of the product-level `rewards` array in /sleeve/info. Order is
/// preserved by <see cref="OrderIndex"/> since the wire shape is an ordered array, not a dict.
/// </summary>
[Owned]
public class SleeveShopProductRewardEntry
{
public int OrderIndex { get; set; }
public int RewardType { get; set; } // Wizard.UserGoods.Type
public long RewardDetailId { get; set; }
public int RewardNumber { get; set; }
}

View File

@@ -0,0 +1,16 @@
using SVSim.Database.Common;
namespace SVSim.Database.Models;
/// <summary>
/// One sleeve-shop series (a themed collection — e.g. series 3019 "BattlePass sleeves",
/// series 3004 "Granblue Fantasy collab"). PK = wire series_id. IsEnabled gates whether
/// /sleeve/info renders this series.
/// </summary>
public class SleeveShopSeriesEntry : BaseEntity<int>
{
public bool IsNew { get; set; }
public bool IsEnabled { get; set; }
public List<SleeveShopProductEntry> Products { get; set; } = new();
}

View File

@@ -70,6 +70,8 @@ public class SVSimDbContext : DbContext
public DbSet<PackConfigEntry> Packs => Set<PackConfigEntry>();
public DbSet<BuildDeckSeriesEntry> BuildDeckSeries => Set<BuildDeckSeriesEntry>();
public DbSet<BuildDeckProductEntry> BuildDeckProducts => Set<BuildDeckProductEntry>();
public DbSet<SleeveShopSeriesEntry> SleeveShopSeries => Set<SleeveShopSeriesEntry>();
public DbSet<SleeveShopProductEntry> SleeveShopProducts => Set<SleeveShopProductEntry>();
public DbSet<MaintenanceCardEntry> MaintenanceCards => Set<MaintenanceCardEntry>();
public DbSet<FeatureMaintenanceEntry> FeatureMaintenances => Set<FeatureMaintenanceEntry>();
public DbSet<PreReleaseInfo> PreReleaseInfos => Set<PreReleaseInfo>();
@@ -180,6 +182,14 @@ public class SVSimDbContext : DbContext
modelBuilder.Entity<BuildDeckProductEntry>().HasIndex(p => p.SeriesId);
modelBuilder.Entity<SleeveShopProductEntry>().OwnsMany(p => p.Rewards);
modelBuilder.Entity<SleeveShopProductEntry>()
.HasOne(p => p.Series)
.WithMany(s => s.Products)
.HasForeignKey(p => p.SeriesId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<SleeveShopProductEntry>().HasIndex(p => p.SeriesId);
modelBuilder.Entity<CardCosmeticReward>(b =>
{
b.HasKey(r => new { r.CardId, r.Type, r.CosmeticId });