Schema: LeaderSkinShopSeries -> Products (owned rewards) + owned SetCompletionRewards on the series; ViewerLeaderSkinSetClaim composite PK (ViewerId, SeriesId) backs the /buy_set_item idempotent-claim check. Importer mirrors SleeveShopImporter: idempotent find-or-create, owned collections rewritten wholesale on rerun. 16 series, 104 products. Controller (extends existing /set with 5 new endpoints): - /products: dict-keyed-by-series_id-string wire shape. is_completed per-viewer, rewards.status from ViewerLeaderSkinSetClaim (0=no set sale, 1=available, 2=claimed) matching client RewardStatus enum. - /buy: single skin, sales_type 1/2 dispatch, 3=>501. - /buy_set: whole series at SetPrice; requires set_sales_status != 0; grants every product's rewards (RewardGrantService idempotent on already-owned cosmetics, so partial-set buys don't double-add). - /buy_set_item: requires viewer owns every skin in series; idempotent on re-claim (returns 200 + empty reward_list, not 400) so client retries don't error. - /ids: flat owned-skin-id list for badge refresh. 496 tests pass (was 486; +10 leader-skin-shop tests). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
116 lines
4.6 KiB
C#
116 lines
4.6 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SVSim.Bootstrap.Models.Seed;
|
|
using SVSim.Database;
|
|
using SVSim.Database.Models;
|
|
|
|
namespace SVSim.Bootstrap.Importers;
|
|
|
|
/// <summary>
|
|
/// Idempotent upsert of the leader-skin-shop catalog from <c>seeds/leader-skin-shop.json</c>.
|
|
/// Mirror of <see cref="SleeveShopImporter"/>. Source is the wire
|
|
/// <c>/leader_skin/products</c> response, extracted via
|
|
/// <c>data_dumps/extract/extract-leader-skin-shop.py</c>. Rows missing from the seed are LEFT INTACT.
|
|
/// </summary>
|
|
public class LeaderSkinShopImporter
|
|
{
|
|
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
|
|
{
|
|
string path = Path.Combine(seedDir, "leader-skin-shop.json");
|
|
var seed = SeedLoader.LoadList<LeaderSkinShopSeriesSeed>(path);
|
|
if (seed.Count == 0)
|
|
{
|
|
Console.WriteLine("[LeaderSkinShopImporter] No seed rows; skipping.");
|
|
return 0;
|
|
}
|
|
|
|
var existingSeries = await context.LeaderSkinShopSeries
|
|
.Include(s => s.SetCompletionRewards)
|
|
.Include(s => s.Products).ThenInclude(p => p.Rewards)
|
|
.ToDictionaryAsync(s => s.Id);
|
|
|
|
int createdSeries = 0, updatedSeries = 0, createdProducts = 0, updatedProducts = 0;
|
|
|
|
foreach (var s in seed)
|
|
{
|
|
if (s.SeriesId == 0) continue;
|
|
|
|
if (!existingSeries.TryGetValue(s.SeriesId, out var series))
|
|
{
|
|
series = new LeaderSkinShopSeriesEntry { Id = s.SeriesId };
|
|
context.LeaderSkinShopSeries.Add(series);
|
|
existingSeries[s.SeriesId] = series;
|
|
createdSeries++;
|
|
}
|
|
else updatedSeries++;
|
|
|
|
series.IsNew = s.IsNew;
|
|
series.IsEnabled = true;
|
|
series.SetSalesStatus = s.SetSalesStatus;
|
|
series.SetPriceCrystal = s.SetPriceCrystal;
|
|
series.SetPriceRupy = s.SetPriceRupy;
|
|
series.SetPriceTicket = s.SetPriceTicket;
|
|
series.SetPriceTicketId = s.SetPriceTicketId;
|
|
// SetCompletionRewardStatus stays at the catalog default 0 — per-viewer claim state
|
|
// is computed at request time from ViewerLeaderSkinSetClaim, not from this column.
|
|
series.SetCompletionRewardStatus = 0;
|
|
|
|
// Replace owned collections wholesale on rerun.
|
|
series.SetCompletionRewards.Clear();
|
|
foreach (var r in s.SetCompletionRewards.OrderBy(r => r.OrderIndex))
|
|
{
|
|
series.SetCompletionRewards.Add(new LeaderSkinShopSeriesRewardEntry
|
|
{
|
|
OrderIndex = r.OrderIndex,
|
|
RewardType = r.RewardType,
|
|
RewardDetailId = r.RewardDetailId,
|
|
RewardNumber = r.RewardNumber,
|
|
});
|
|
}
|
|
|
|
var existingProducts = series.Products.ToDictionary(p => p.Id);
|
|
foreach (var p in s.Products)
|
|
{
|
|
if (p.ProductId == 0) continue;
|
|
|
|
if (!existingProducts.TryGetValue(p.ProductId, out var product))
|
|
{
|
|
product = new LeaderSkinShopProductEntry { Id = p.ProductId };
|
|
series.Products.Add(product);
|
|
createdProducts++;
|
|
}
|
|
else updatedProducts++;
|
|
|
|
product.SeriesId = s.SeriesId;
|
|
product.LeaderSkinId = p.LeaderSkinId;
|
|
product.ProductNameKey = p.ProductNameKey;
|
|
product.IntroductionKey = p.IntroductionKey;
|
|
product.CvNameKey = p.CvNameKey;
|
|
product.SinglePriceCrystal = p.SinglePriceCrystal;
|
|
product.SinglePriceRupy = p.SinglePriceRupy;
|
|
product.SinglePriceTicket = p.SinglePriceTicket;
|
|
product.TicketNumber = p.TicketNumber;
|
|
product.TicketItemId = p.TicketItemId;
|
|
product.IsEnabled = true;
|
|
|
|
product.Rewards.Clear();
|
|
foreach (var r in p.Rewards.OrderBy(r => r.OrderIndex))
|
|
{
|
|
product.Rewards.Add(new LeaderSkinShopProductRewardEntry
|
|
{
|
|
OrderIndex = r.OrderIndex,
|
|
RewardType = r.RewardType,
|
|
RewardDetailId = r.RewardDetailId,
|
|
RewardNumber = r.RewardNumber,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
await context.SaveChangesAsync();
|
|
Console.WriteLine(
|
|
$"[LeaderSkinShopImporter] series +{createdSeries}/~{updatedSeries}, " +
|
|
$"products +{createdProducts}/~{updatedProducts}");
|
|
return createdSeries + updatedSeries;
|
|
}
|
|
}
|