Split into Budget.Core / Budget.Infrastructure / Budget.Api projects

Budget.Core: entities, DTOs, enums, FrequencyCalculator (no EF/ASP.NET deps)
Budget.Infrastructure: AppDbContext, migrations, BudgetAuthorizationService
Budget.Api: controllers, middleware, Program.cs — references both projects

EF and Npgsql packages moved to Infrastructure; Api retains only JwtBearer,
HealthChecks, and EF.Design (needed for dotnet ef CLI). Dockerfile updated
to copy all three project directories before publishing. Migration namespaces
updated from Budget.Api.Data.* to Budget.Infrastructure.Data.* and model
type strings updated to Budget.Core.Models.* in the snapshot.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Spencer Twaddle
2026-05-02 16:30:31 -05:00
parent c3d1420c4c
commit 087fbdd176
37 changed files with 826 additions and 78 deletions
@@ -0,0 +1,60 @@
using Budget.Core.Models;
using Microsoft.EntityFrameworkCore;
namespace Budget.Infrastructure.Data;
public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(options)
{
public DbSet<Budget.Core.Models.Budget> Budgets => Set<Budget.Core.Models.Budget>();
public DbSet<Income> Incomes => Set<Income>();
public DbSet<Outgo> Outgos => Set<Outgo>();
public DbSet<KnownUser> KnownUsers => Set<KnownUser>();
public DbSet<BudgetShare> BudgetShares => Set<BudgetShare>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Budget.Core.Models.Budget>(b =>
{
b.HasKey(x => x.Id);
b.Property(x => x.Name).IsRequired().HasMaxLength(200);
b.Property(x => x.OwnerUserId).IsRequired().HasMaxLength(200);
b.Property(x => x.EffectiveTaxRate).HasPrecision(5, 4);
b.HasMany(x => x.Incomes).WithOne(i => i.Budget).HasForeignKey(i => i.BudgetId).OnDelete(DeleteBehavior.Cascade);
b.HasMany(x => x.Outgos).WithOne(o => o.Budget).HasForeignKey(o => o.BudgetId).OnDelete(DeleteBehavior.Cascade);
b.HasMany(x => x.Shares).WithOne(s => s.Budget).HasForeignKey(s => s.BudgetId).OnDelete(DeleteBehavior.Cascade);
});
modelBuilder.Entity<Income>(b =>
{
b.HasKey(x => x.Id);
b.Property(x => x.Name).IsRequired().HasMaxLength(200);
b.Property(x => x.Amount).HasPrecision(18, 2);
});
modelBuilder.Entity<Outgo>(b =>
{
b.HasKey(x => x.Id);
b.Property(x => x.Name).IsRequired().HasMaxLength(200);
b.Property(x => x.Category).HasMaxLength(100);
b.Property(x => x.PaymentSource).HasMaxLength(100);
b.Property(x => x.Notes).HasMaxLength(1000);
b.Property(x => x.Amount).HasPrecision(18, 2);
});
modelBuilder.Entity<KnownUser>(b =>
{
b.HasKey(x => x.Id);
b.Property(x => x.Id).HasMaxLength(200);
b.Property(x => x.Email).IsRequired().HasMaxLength(200);
b.Property(x => x.Name).IsRequired().HasMaxLength(200);
});
modelBuilder.Entity<BudgetShare>(b =>
{
b.HasKey(x => x.Id);
b.Property(x => x.SharedWithUserId).HasMaxLength(200);
b.Property(x => x.SharedWithEmail).IsRequired().HasMaxLength(200);
b.HasIndex(x => new { x.BudgetId, x.SharedWithEmail }).IsUnique();
});
}
}