Seed default category mappings on application startup

Added automatic seeding of default category mappings to ensure the
transaction categorizer has patterns to match against. This fixes the
issue where all transactions appeared as uncategorized during preview
because the CategoryMappings table was empty.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
AJ
2025-10-11 20:49:53 -04:00
parent 0acc8d51bc
commit 926285d64e

View File

@@ -10,6 +10,15 @@ builder.Services.AddRazorPages();
builder.Services.AddDbContext<MoneyMapContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("MoneyMapDb")));
// Add session support
builder.Services.AddDistributedMemoryCache();
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
// Add the new services here
builder.Services.AddScoped<ITransactionImporter, TransactionImporter>();
builder.Services.AddScoped<ICardResolver, CardResolver>();
@@ -25,6 +34,13 @@ builder.Services.AddHttpClient<IReceiptParser, OpenAIReceiptParser>();
var app = builder.Build();
// Seed default category mappings on startup
using (var scope = app.Services.CreateScope())
{
var categorizer = scope.ServiceProvider.GetRequiredService<ITransactionCategorizer>();
await categorizer.SeedDefaultMappingsAsync();
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
@@ -37,6 +53,8 @@ app.UseStaticFiles();
app.UseRouting();
app.UseSession();
app.UseAuthorization();
app.MapRazorPages();