refactor(bootstrap): migrate payment items to seed file
Lifts ImportPaymentItems out of GlobalsImporter into a dedicated PaymentItemImporter driven by Data/seeds/payment-items.json. Wired into Program.cs and SVSimTestFactory.SeedGlobalsAsync after PracticeOpponentImporter. Drops the prod-capture file in favor of the extractor pipeline. Canonical 4-test suite (basic, idempotent, leave-untouched, skip-zero) keeps the dict-in-sync upsert pattern Task 2 established. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,6 @@ public class GlobalsImporter
|
||||
JsonElement? loadIndex = LoadCapture(capturesDir, "load-index");
|
||||
JsonElement? mypageIndex = LoadCapture(capturesDir, "mypage-index");
|
||||
JsonElement? deckInfo = LoadCapture(capturesDir, "deck-info");
|
||||
JsonElement? paymentItemList = LoadCapture(capturesDir, "payment-item-list");
|
||||
JsonElement? packInfo = LoadCapture(capturesDir, "pack-info");
|
||||
JsonElement? basicPuzzleInfo = LoadCapture(capturesDir, "basic-puzzle-info");
|
||||
JsonElement? basicPuzzleMission = LoadCapture(capturesDir, "basic-puzzle-mission");
|
||||
@@ -69,11 +68,6 @@ public class GlobalsImporter
|
||||
total += await ImportDefaultDecks(context, deckInfo.Value);
|
||||
}
|
||||
|
||||
if (paymentItemList.HasValue)
|
||||
{
|
||||
total += await ImportPaymentItems(context, paymentItemList.Value);
|
||||
}
|
||||
|
||||
if (packInfo.HasValue)
|
||||
{
|
||||
total += await ImportPacks(context, packInfo.Value);
|
||||
@@ -709,54 +703,6 @@ public class GlobalsImporter
|
||||
return created + updated;
|
||||
}
|
||||
|
||||
// ---------- Payment: Item list (Steam/PC storefront, dict-keyed by store_product_id) ----------
|
||||
|
||||
private async Task<int> ImportPaymentItems(SVSimDbContext context, JsonElement payment)
|
||||
{
|
||||
// The payment-item-list capture's `data` IS the product dict (no nested key like banner/colosseum).
|
||||
// LoadCapture already unwrapped `data` for us, so iterate the dict directly.
|
||||
if (payment.ValueKind != JsonValueKind.Object) return 0;
|
||||
|
||||
var existing = await context.PaymentItems.ToDictionaryAsync(e => e.Id);
|
||||
int created = 0, updated = 0;
|
||||
foreach (var kv in payment.EnumerateObject())
|
||||
{
|
||||
var v = kv.Value;
|
||||
if (v.ValueKind != JsonValueKind.Object) continue;
|
||||
|
||||
int recordId = GetInt(v, "record_id");
|
||||
if (recordId == 0) continue;
|
||||
|
||||
var entry = existing.TryGetValue(recordId, out var ex) ? ex : new PaymentItemEntry { Id = recordId };
|
||||
entry.ProductId = GetInt(v, "id");
|
||||
entry.StoreProductId = GetLong(v, "store_product_id");
|
||||
entry.Name = GetString(v, "name");
|
||||
entry.Text = GetString(v, "text");
|
||||
entry.Price = ParseDecimal(GetString(v, "price"));
|
||||
entry.ChargeCrystalNum = GetInt(v, "charge_crystal_num");
|
||||
entry.FreeCrystalNum = GetInt(v, "free_crystal_num");
|
||||
entry.PurchaseLimit = GetInt(v, "purchase_limit");
|
||||
entry.SpecialShopFlag = GetInt(v, "special_shop_flag");
|
||||
entry.ImageName = GetString(v, "image_name");
|
||||
entry.StartTime = ParseWireDateTime(GetString(v, "start_time"));
|
||||
entry.EndTime = ParseWireDateTime(GetString(v, "end_time"));
|
||||
entry.RemainingTime = GetInt(v, "remaining_time");
|
||||
entry.IsResaleProduct = GetInt(v, "is_resale_product");
|
||||
// resale_start_date is "" when unset — store null rather than DateTime.MinValue so the
|
||||
// controller can decide whether to emit "" or a real date string.
|
||||
string resaleRaw = GetString(v, "resale_start_date");
|
||||
entry.ResaleStartDate = string.IsNullOrWhiteSpace(resaleRaw) ? null : ParseWireDateTime(resaleRaw);
|
||||
|
||||
if (ex is null) { context.PaymentItems.Add(entry); created++; }
|
||||
else updated++;
|
||||
}
|
||||
Console.WriteLine($"[GlobalsImporter] PaymentItems: +{created}/~{updated}");
|
||||
return created + updated;
|
||||
}
|
||||
|
||||
private static decimal ParseDecimal(string s) =>
|
||||
decimal.TryParse(s, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out var d) ? d : 0m;
|
||||
|
||||
// ---------- Pack catalog ----------
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user