Prebuilt deck purchasing and fixes
This commit is contained in:
2834
SVSim.Database/Migrations/20260526043148_AddBuildDeck.Designer.cs
generated
Normal file
2834
SVSim.Database/Migrations/20260526043148_AddBuildDeck.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
191
SVSim.Database/Migrations/20260526043148_AddBuildDeck.cs
Normal file
191
SVSim.Database/Migrations/20260526043148_AddBuildDeck.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace SVSim.Database.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddBuildDeck : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildDeckSeries",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false),
|
||||
OrderIndex = table.Column<int>(type: "integer", nullable: false),
|
||||
NameKey = table.Column<string>(type: "text", nullable: false),
|
||||
IntroKey = table.Column<string>(type: "text", nullable: false),
|
||||
TitlePath = table.Column<string>(type: "text", nullable: false),
|
||||
DrumrollPath = table.Column<string>(type: "text", 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_BuildDeckSeries", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ViewerBuildDeckProductPurchase",
|
||||
columns: table => new
|
||||
{
|
||||
ViewerId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ProductId = table.Column<int>(type: "integer", nullable: false),
|
||||
PurchaseCount = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ViewerBuildDeckProductPurchase", x => new { x.ViewerId, x.Id });
|
||||
table.ForeignKey(
|
||||
name: "FK_ViewerBuildDeckProductPurchase_Viewers_ViewerId",
|
||||
column: x => x.ViewerId,
|
||||
principalTable: "Viewers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildDeckProducts",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false),
|
||||
SeriesId = table.Column<int>(type: "integer", nullable: false),
|
||||
LeaderId = table.Column<int>(type: "integer", nullable: false),
|
||||
DeckCode = table.Column<string>(type: "text", nullable: false),
|
||||
ProductNameKey = table.Column<string>(type: "text", nullable: false),
|
||||
FeaturedCardId = table.Column<long>(type: "bigint", nullable: false),
|
||||
PurchaseNumMax = table.Column<int>(type: "integer", nullable: false),
|
||||
IntroPriceCrystal = table.Column<int>(type: "integer", nullable: true),
|
||||
RegularPriceCrystal = table.Column<int>(type: "integer", nullable: true),
|
||||
IntroPriceRupy = table.Column<int>(type: "integer", nullable: true),
|
||||
RegularPriceRupy = 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_BuildDeckProducts", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildDeckProducts_BuildDeckSeries_SeriesId",
|
||||
column: x => x.SeriesId,
|
||||
principalTable: "BuildDeckSeries",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildDeckSeriesRewardEntry",
|
||||
columns: table => new
|
||||
{
|
||||
BuildDeckSeriesEntryId = table.Column<int>(type: "integer", nullable: false),
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
TierIndex = table.Column<int>(type: "integer", nullable: false),
|
||||
ItemIndex = 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),
|
||||
MessageId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BuildDeckSeriesRewardEntry", x => new { x.BuildDeckSeriesEntryId, x.Id });
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildDeckSeriesRewardEntry_BuildDeckSeries_BuildDeckSeriesE~",
|
||||
column: x => x.BuildDeckSeriesEntryId,
|
||||
principalTable: "BuildDeckSeries",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildDeckProductCardEntry",
|
||||
columns: table => new
|
||||
{
|
||||
BuildDeckProductEntryId = table.Column<int>(type: "integer", nullable: false),
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
CardId = table.Column<long>(type: "bigint", nullable: false),
|
||||
Number = table.Column<int>(type: "integer", nullable: false),
|
||||
IsSpot = table.Column<bool>(type: "boolean", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BuildDeckProductCardEntry", x => new { x.BuildDeckProductEntryId, x.Id });
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildDeckProductCardEntry_BuildDeckProducts_BuildDeckProduc~",
|
||||
column: x => x.BuildDeckProductEntryId,
|
||||
principalTable: "BuildDeckProducts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BuildDeckProductRewardEntry",
|
||||
columns: table => new
|
||||
{
|
||||
BuildDeckProductEntryId = table.Column<int>(type: "integer", nullable: false),
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
RewardIndex = 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),
|
||||
MessageId = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BuildDeckProductRewardEntry", x => new { x.BuildDeckProductEntryId, x.Id });
|
||||
table.ForeignKey(
|
||||
name: "FK_BuildDeckProductRewardEntry_BuildDeckProducts_BuildDeckProd~",
|
||||
column: x => x.BuildDeckProductEntryId,
|
||||
principalTable: "BuildDeckProducts",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BuildDeckProducts_SeriesId",
|
||||
table: "BuildDeckProducts",
|
||||
column: "SeriesId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ViewerBuildDeckProductPurchase_ViewerId_ProductId",
|
||||
table: "ViewerBuildDeckProductPurchase",
|
||||
columns: new[] { "ViewerId", "ProductId" },
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BuildDeckProductCardEntry");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BuildDeckProductRewardEntry");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BuildDeckSeriesRewardEntry");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ViewerBuildDeckProductPurchase");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BuildDeckProducts");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BuildDeckSeries");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -540,6 +540,100 @@ namespace SVSim.Database.Migrations
|
||||
b.ToTable("Battlefields");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.BuildDeckProductEntry", 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<string>("DeckCode")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<long>("FeaturedCardId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b.Property<int?>("IntroPriceCrystal")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("IntroPriceRupy")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<int>("LeaderId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("ProductNameKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("PurchaseNumMax")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("RegularPriceCrystal")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int?>("RegularPriceRupy")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("SeriesId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("SeriesId");
|
||||
|
||||
b.ToTable("BuildDeckProducts");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.BuildDeckSeriesEntry", 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<string>("DrumrollPath")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("IntroKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<bool>("IsEnabled")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<bool>("IsNew")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b.Property<string>("NameKey")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("OrderIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("TitlePath")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("BuildDeckSeries");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.CardCosmeticReward", b =>
|
||||
{
|
||||
b.Property<long>("CardId")
|
||||
@@ -1975,6 +2069,125 @@ namespace SVSim.Database.Migrations
|
||||
b.Navigation("World");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.BuildDeckProductEntry", b =>
|
||||
{
|
||||
b.HasOne("SVSim.Database.Models.BuildDeckSeriesEntry", "Series")
|
||||
.WithMany("Products")
|
||||
.HasForeignKey("SeriesId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.OwnsMany("SVSim.Database.Models.BuildDeckProductCardEntry", "Cards", b1 =>
|
||||
{
|
||||
b1.Property<int>("BuildDeckProductEntryId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
|
||||
|
||||
b1.Property<long>("CardId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<bool>("IsSpot")
|
||||
.HasColumnType("boolean");
|
||||
|
||||
b1.Property<int>("Number")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.HasKey("BuildDeckProductEntryId", "Id");
|
||||
|
||||
b1.ToTable("BuildDeckProductCardEntry");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BuildDeckProductEntryId");
|
||||
});
|
||||
|
||||
b.OwnsMany("SVSim.Database.Models.BuildDeckProductRewardEntry", "Rewards", b1 =>
|
||||
{
|
||||
b1.Property<int>("BuildDeckProductEntryId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
|
||||
|
||||
b1.Property<int>("MessageId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<long>("RewardDetailId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<int>("RewardIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("RewardNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("RewardType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.HasKey("BuildDeckProductEntryId", "Id");
|
||||
|
||||
b1.ToTable("BuildDeckProductRewardEntry");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BuildDeckProductEntryId");
|
||||
});
|
||||
|
||||
b.Navigation("Cards");
|
||||
|
||||
b.Navigation("Rewards");
|
||||
|
||||
b.Navigation("Series");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.BuildDeckSeriesEntry", b =>
|
||||
{
|
||||
b.OwnsMany("SVSim.Database.Models.BuildDeckSeriesRewardEntry", "SeriesRewards", b1 =>
|
||||
{
|
||||
b1.Property<int>("BuildDeckSeriesEntryId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
|
||||
|
||||
b1.Property<int>("ItemIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("MessageId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<long>("RewardDetailId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<int>("RewardNumber")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("RewardType")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("TierIndex")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.HasKey("BuildDeckSeriesEntryId", "Id");
|
||||
|
||||
b1.ToTable("BuildDeckSeriesRewardEntry");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BuildDeckSeriesEntryId");
|
||||
});
|
||||
|
||||
b.Navigation("SeriesRewards");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.CardCosmeticReward", b =>
|
||||
{
|
||||
b.HasOne("SVSim.Database.Models.ShadowverseCardEntry", "Card")
|
||||
@@ -2322,6 +2535,34 @@ namespace SVSim.Database.Migrations
|
||||
b1.Navigation("Viewer");
|
||||
});
|
||||
|
||||
b.OwnsMany("SVSim.Database.Models.ViewerBuildDeckProductPurchase", "BuildDeckPurchases", b1 =>
|
||||
{
|
||||
b1.Property<long>("ViewerId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b1.Property<int>("Id"));
|
||||
|
||||
b1.Property<int>("ProductId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.Property<int>("PurchaseCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b1.HasKey("ViewerId", "Id");
|
||||
|
||||
b1.HasIndex("ViewerId", "ProductId")
|
||||
.IsUnique();
|
||||
|
||||
b1.ToTable("ViewerBuildDeckProductPurchase");
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("ViewerId");
|
||||
});
|
||||
|
||||
b.OwnsMany("SVSim.Database.Models.ViewerClassData", "Classes", b1 =>
|
||||
{
|
||||
b1.Property<long>("ViewerId")
|
||||
@@ -2523,6 +2764,8 @@ namespace SVSim.Database.Migrations
|
||||
.HasForeignKey("ViewerId");
|
||||
});
|
||||
|
||||
b.Navigation("BuildDeckPurchases");
|
||||
|
||||
b.Navigation("Cards");
|
||||
|
||||
b.Navigation("Classes");
|
||||
@@ -2558,6 +2801,11 @@ namespace SVSim.Database.Migrations
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.BuildDeckSeriesEntry", b =>
|
||||
{
|
||||
b.Navigation("Products");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("SVSim.Database.Models.ClassEntry", b =>
|
||||
{
|
||||
b.Navigation("LeaderSkins");
|
||||
|
||||
17
SVSim.Database/Models/BuildDeckProductCardEntry.cs
Normal file
17
SVSim.Database/Models/BuildDeckProductCardEntry.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// One card in a prebuilt-deck product's 40-card list. Owned by BuildDeckProductEntry.
|
||||
/// Shape mirrors `build_deck_package_master.csv` rows: (ProductId, CardId, Number, IsSpot).
|
||||
/// IsSpot=true marks the special prize/featured cards rendered in the separate _spotCardRoot
|
||||
/// panel by BuildDeckProductDetail.cs.
|
||||
/// </summary>
|
||||
[Owned]
|
||||
public class BuildDeckProductCardEntry
|
||||
{
|
||||
public long CardId { get; set; }
|
||||
public int Number { get; set; }
|
||||
public bool IsSpot { get; set; }
|
||||
}
|
||||
32
SVSim.Database/Models/BuildDeckProductEntry.cs
Normal file
32
SVSim.Database/Models/BuildDeckProductEntry.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using SVSim.Database.Common;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// One purchasable prebuilt-deck product. PK = wire product_id. FK SeriesId.
|
||||
/// Pricing columns are nullable; either Crystal or Rupy pair (or both, both zero for free) must
|
||||
/// be populated for an enabled product. The Intro/Regular pair captures the two-tier pricing
|
||||
/// pattern: Intro applies to the first purchase, Regular to subsequent. For PurchaseNumMax=1
|
||||
/// products, Regular stays null and only Intro is ever served.
|
||||
/// </summary>
|
||||
public class BuildDeckProductEntry : BaseEntity<int>
|
||||
{
|
||||
public int SeriesId { get; set; }
|
||||
public int LeaderId { get; set; }
|
||||
public string DeckCode { get; set; } = string.Empty;
|
||||
public string ProductNameKey { get; set; } = string.Empty; // BDPN_*
|
||||
public long FeaturedCardId { get; set; }
|
||||
public int PurchaseNumMax { get; set; }
|
||||
|
||||
public int? IntroPriceCrystal { get; set; }
|
||||
public int? RegularPriceCrystal { get; set; }
|
||||
public int? IntroPriceRupy { get; set; }
|
||||
public int? RegularPriceRupy { get; set; }
|
||||
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public List<BuildDeckProductCardEntry> Cards { get; set; } = new();
|
||||
public List<BuildDeckProductRewardEntry> Rewards { get; set; } = new();
|
||||
|
||||
public BuildDeckSeriesEntry? Series { get; set; }
|
||||
}
|
||||
18
SVSim.Database/Models/BuildDeckProductRewardEntry.cs
Normal file
18
SVSim.Database/Models/BuildDeckProductRewardEntry.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// One per-buy reward attached to a prebuilt-deck product. Owned by BuildDeckProductEntry.
|
||||
/// Wire shape: one entry of the product-level `rewards` dict in /build_deck/info, keyed by
|
||||
/// RewardIndex (the wire string keys "1","2","3").
|
||||
/// </summary>
|
||||
[Owned]
|
||||
public class BuildDeckProductRewardEntry
|
||||
{
|
||||
public int RewardIndex { get; set; }
|
||||
public int RewardType { get; set; } // Wizard.UserGoods.Type
|
||||
public long RewardDetailId { get; set; }
|
||||
public int RewardNumber { get; set; }
|
||||
public int MessageId { get; set; }
|
||||
}
|
||||
22
SVSim.Database/Models/BuildDeckSeriesEntry.cs
Normal file
22
SVSim.Database/Models/BuildDeckSeriesEntry.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using SVSim.Database.Common;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// One prebuilt-deck series ("Structure Deck Set 7", "Trial 19", etc.). PK = wire series_id.
|
||||
/// IsEnabled gates whether /build_deck/info renders this series — disabled rows are placeholder
|
||||
/// stubs created from the client CSV until we capture a /info response that enriches them.
|
||||
/// </summary>
|
||||
public class BuildDeckSeriesEntry : BaseEntity<int>
|
||||
{
|
||||
public int OrderIndex { get; set; } // wire order_id; controls display order
|
||||
public string NameKey { get; set; } = string.Empty; // BDSSN_*
|
||||
public string IntroKey { get; set; } = string.Empty; // BDSI_*
|
||||
public string TitlePath { get; set; } = string.Empty;
|
||||
public string DrumrollPath { get; set; } = string.Empty;
|
||||
public bool IsNew { get; set; }
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
public List<BuildDeckSeriesRewardEntry> SeriesRewards { get; set; } = new();
|
||||
public List<BuildDeckProductEntry> Products { get; set; } = new();
|
||||
}
|
||||
20
SVSim.Database/Models/BuildDeckSeriesRewardEntry.cs
Normal file
20
SVSim.Database/Models/BuildDeckSeriesRewardEntry.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// One tier-reward item attached to a prebuilt-deck series. Owned by BuildDeckSeriesEntry.
|
||||
/// Wire shape: flattened from /build_deck/info's `series_rewards` dict — each tier (keyed
|
||||
/// by total-purchases-from-series threshold) carries a list of rewards; this row is one
|
||||
/// (TierIndex, ItemIndex) cell.
|
||||
/// </summary>
|
||||
[Owned]
|
||||
public class BuildDeckSeriesRewardEntry
|
||||
{
|
||||
public int TierIndex { get; set; } // 1, 2, 3, ... — unlock threshold
|
||||
public int ItemIndex { get; set; } // ordinal within tier
|
||||
public int RewardType { get; set; }
|
||||
public long RewardDetailId { get; set; }
|
||||
public int RewardNumber { get; set; }
|
||||
public int MessageId { get; set; }
|
||||
}
|
||||
@@ -57,6 +57,8 @@ public class Viewer : BaseEntity<long>
|
||||
|
||||
public List<ViewerPackOpenCount> PackOpenCounts { get; set; } = new List<ViewerPackOpenCount>();
|
||||
|
||||
public List<ViewerBuildDeckProductPurchase> BuildDeckPurchases { get; set; } = new List<ViewerBuildDeckProductPurchase>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region Navigation Properties
|
||||
|
||||
14
SVSim.Database/Models/ViewerBuildDeckProductPurchase.cs
Normal file
14
SVSim.Database/Models/ViewerBuildDeckProductPurchase.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SVSim.Database.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Per-viewer, per-product purchase counter. Owned collection on Viewer.
|
||||
/// Unique (ViewerId, ProductId) enforced in SVSimDbContext per project_owned_collection_unique_index.
|
||||
/// </summary>
|
||||
[Owned]
|
||||
public class ViewerBuildDeckProductPurchase
|
||||
{
|
||||
public int ProductId { get; set; }
|
||||
public int PurchaseCount { get; set; }
|
||||
}
|
||||
67
SVSim.Database/Repositories/BuildDeck/BuildDeckRepository.cs
Normal file
67
SVSim.Database/Repositories/BuildDeck/BuildDeckRepository.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.BuildDeck;
|
||||
|
||||
public class BuildDeckRepository : IBuildDeckRepository
|
||||
{
|
||||
private readonly SVSimDbContext _db;
|
||||
public BuildDeckRepository(SVSimDbContext db) { _db = db; }
|
||||
|
||||
public async Task<List<BuildDeckSeriesEntry>> GetEnabledCatalog(int addSeriesId)
|
||||
{
|
||||
var q = _db.BuildDeckSeries
|
||||
.Include(s => s.SeriesRewards)
|
||||
.Include(s => s.Products.Where(p => p.IsEnabled))
|
||||
.ThenInclude(p => p.Cards)
|
||||
.Include(s => s.Products.Where(p => p.IsEnabled))
|
||||
.ThenInclude(p => p.Rewards)
|
||||
.Where(s => s.IsEnabled)
|
||||
.AsSplitQuery();
|
||||
|
||||
if (addSeriesId != 0)
|
||||
{
|
||||
q = q.Where(s => s.Id == addSeriesId);
|
||||
}
|
||||
|
||||
var list = await q.ToListAsync();
|
||||
list.Sort((a, b) => b.OrderIndex.CompareTo(a.OrderIndex));
|
||||
return list;
|
||||
}
|
||||
|
||||
public async Task<BuildDeckProductEntry?> GetProduct(int productId) =>
|
||||
await _db.BuildDeckProducts
|
||||
.Include(p => p.Cards)
|
||||
.Include(p => p.Rewards)
|
||||
.Include(p => p.Series).ThenInclude(s => s!.SeriesRewards)
|
||||
.Include(p => p.Series).ThenInclude(s => s!.Products)
|
||||
.AsSplitQuery()
|
||||
.FirstOrDefaultAsync(p => p.Id == productId);
|
||||
|
||||
public async Task<Dictionary<int, ViewerBuildDeckProductPurchase>> GetPurchasesForViewer(long viewerId)
|
||||
{
|
||||
var viewer = await _db.Viewers
|
||||
.Include(v => v.BuildDeckPurchases)
|
||||
.FirstOrDefaultAsync(v => v.Id == viewerId);
|
||||
return viewer?.BuildDeckPurchases.ToDictionary(p => p.ProductId) ?? new();
|
||||
}
|
||||
|
||||
public async Task<int> IncrementPurchaseCount(long viewerId, int productId)
|
||||
{
|
||||
var viewer = await _db.Viewers
|
||||
.Include(v => v.BuildDeckPurchases)
|
||||
.FirstAsync(v => v.Id == viewerId);
|
||||
var row = viewer.BuildDeckPurchases.FirstOrDefault(p => p.ProductId == productId);
|
||||
if (row is null)
|
||||
{
|
||||
row = new ViewerBuildDeckProductPurchase { ProductId = productId, PurchaseCount = 1 };
|
||||
viewer.BuildDeckPurchases.Add(row);
|
||||
}
|
||||
else
|
||||
{
|
||||
row.PurchaseCount += 1;
|
||||
}
|
||||
await _db.SaveChangesAsync();
|
||||
return row.PurchaseCount;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using SVSim.Database.Models;
|
||||
|
||||
namespace SVSim.Database.Repositories.BuildDeck;
|
||||
|
||||
public interface IBuildDeckRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// Load enabled series (filtered by addSeriesId when non-zero) with all owned children
|
||||
/// for /build_deck/info. Series and per-series products are sorted by OrderIndex desc.
|
||||
/// </summary>
|
||||
Task<List<BuildDeckSeriesEntry>> GetEnabledCatalog(int addSeriesId);
|
||||
|
||||
/// <summary>
|
||||
/// Load a single product (with Series + Cards + Rewards + Series.SeriesRewards) by id.
|
||||
/// Returns null if absent. Used by /build_deck/buy and /build_deck/get_purchase_count.
|
||||
/// </summary>
|
||||
Task<BuildDeckProductEntry?> GetProduct(int productId);
|
||||
|
||||
/// <summary>
|
||||
/// Per-viewer purchase counter snapshot. Key = product_id.
|
||||
/// </summary>
|
||||
Task<Dictionary<int, ViewerBuildDeckProductPurchase>> GetPurchasesForViewer(long viewerId);
|
||||
|
||||
/// <summary>
|
||||
/// Increment the (ViewerId, ProductId) purchase counter by 1 (insert if absent).
|
||||
/// Returns the new total.
|
||||
/// </summary>
|
||||
Task<int> IncrementPurchaseCount(long viewerId, int productId);
|
||||
}
|
||||
@@ -59,6 +59,8 @@ public class SVSimDbContext : DbContext
|
||||
public DbSet<SpecialDeckFormatEntry> SpecialDeckFormats => Set<SpecialDeckFormatEntry>();
|
||||
public DbSet<PaymentItemEntry> PaymentItems => Set<PaymentItemEntry>();
|
||||
public DbSet<PackConfigEntry> Packs => Set<PackConfigEntry>();
|
||||
public DbSet<BuildDeckSeriesEntry> BuildDeckSeries => Set<BuildDeckSeriesEntry>();
|
||||
public DbSet<BuildDeckProductEntry> BuildDeckProducts => Set<BuildDeckProductEntry>();
|
||||
public DbSet<MaintenanceCardEntry> MaintenanceCards => Set<MaintenanceCardEntry>();
|
||||
public DbSet<FeatureMaintenanceEntry> FeatureMaintenances => Set<FeatureMaintenanceEntry>();
|
||||
public DbSet<PreReleaseInfo> PreReleaseInfos => Set<PreReleaseInfo>();
|
||||
@@ -141,6 +143,23 @@ public class SVSimDbContext : DbContext
|
||||
b.HasIndex("ViewerId", "ItemId").IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<Viewer>().OwnsMany(v => v.BuildDeckPurchases, b =>
|
||||
{
|
||||
b.HasIndex("ViewerId", "ProductId").IsUnique();
|
||||
});
|
||||
|
||||
modelBuilder.Entity<BuildDeckSeriesEntry>().OwnsMany(s => s.SeriesRewards);
|
||||
modelBuilder.Entity<BuildDeckProductEntry>().OwnsMany(p => p.Cards);
|
||||
modelBuilder.Entity<BuildDeckProductEntry>().OwnsMany(p => p.Rewards);
|
||||
|
||||
modelBuilder.Entity<BuildDeckProductEntry>()
|
||||
.HasOne(p => p.Series)
|
||||
.WithMany(s => s.Products)
|
||||
.HasForeignKey(p => p.SeriesId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
modelBuilder.Entity<BuildDeckProductEntry>().HasIndex(p => p.SeriesId);
|
||||
|
||||
modelBuilder.Entity<CardCosmeticReward>(b =>
|
||||
{
|
||||
b.HasKey(r => new { r.CardId, r.Type, r.CosmeticId });
|
||||
|
||||
@@ -14,14 +14,26 @@ namespace SVSim.Database.Services;
|
||||
public sealed record GrantedReward(int RewardType, long RewardId, int RewardNum);
|
||||
|
||||
/// <summary>
|
||||
/// Single canonical grant primitive. Switch on <see cref="UserGoodsType"/>, mutate the
|
||||
/// appropriate viewer collection / <see cref="ViewerCurrency"/> field, and return the
|
||||
/// wire-shape entries the caller should embed in its response's reward_list.
|
||||
/// Single canonical grant primitive for every <see cref="UserGoodsType"/> the server hands to a
|
||||
/// viewer. Switch on the type, mutate the appropriate viewer collection / <see cref="ViewerCurrency"/>
|
||||
/// field, return the wire-shape entries to embed in the response's <c>reward_list</c>.
|
||||
///
|
||||
/// <para>
|
||||
/// <b>DO NOT reimplement reward dispatch in a controller or new helper.</b> This service handles
|
||||
/// RedEther, Crystal, Item, Card (with <see cref="CardCosmeticReward"/> cascade), Sleeve, Emblem,
|
||||
/// Degree, Rupy, Skin, MyPageBG — everything except SpotCard (TODO). Endpoint code that takes a
|
||||
/// list of <c>(type, id, num)</c> tuples should iterate and call <see cref="ApplyAsync"/>
|
||||
/// per tuple — never switch on type yourself, never filter to "only card-typed rewards", never
|
||||
/// build a second dispatch table. Past duplicate implementations (ICardAcquisitionService in the
|
||||
/// EmulatedEntrypoint project, the first pass at /build_deck/buy) all silently dropped subsets of
|
||||
/// types and produced the same bug: wire reward visible but viewer's collection unchanged. When a
|
||||
/// new reward type comes up, add a case here. See <c>feedback_reward_grant_service</c> memory.
|
||||
/// </para>
|
||||
///
|
||||
/// Card grants additionally run the <see cref="CardCosmeticReward"/> cascade: any cosmetic
|
||||
/// associated with the granted card that the viewer doesn't yet own is granted too, and
|
||||
/// produces an additional entry in the returned list. That's why the return type is a list:
|
||||
/// most types produce one entry, Card produces 1 + N.
|
||||
/// associated with the granted card that the viewer doesn't yet own is granted too, and produces
|
||||
/// an additional entry in the returned list. That's why the return type is a list: most types
|
||||
/// produce one entry, Card produces 1 + N.
|
||||
///
|
||||
/// Caller is responsible for <see cref="SVSimDbContext.SaveChangesAsync(System.Threading.CancellationToken)"/> —
|
||||
/// this service only mutates the in-memory graph so a controller can stack several grants in
|
||||
|
||||
Reference in New Issue
Block a user