Adding journal entries and database tables. Increased starting balances.

This commit is contained in:
2026-07-15 12:08:28 +02:00
parent 0de38ef2df
commit 656f545281
13 changed files with 498 additions and 34 deletions
@@ -6,6 +6,7 @@ namespace FinancialApi.Infrastructure;
public class AccountDbContext(DbContextOptions<AccountDbContext> options) : DbContext(options)
{
public DbSet<Account> Accounts => Set<Account>();
public DbSet<JournalEntry> JournalEntries => Set<JournalEntry>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -13,8 +14,21 @@ public class AccountDbContext(DbContextOptions<AccountDbContext> options) : DbCo
.HasKey(x => x.Id);
modelBuilder.Entity<Account>().HasData(
new Account(1, 100.00m),
new Account(2, 500.00m)
new Account(1, 10000000.00m, "Credit"),
new Account(2, 50000000.00m, "Liability"),
new Account(99999, 0.00m, "Revenue")
);
modelBuilder.Entity<JournalEntry>(builder =>
{
builder.HasKey(x => x.Id);
builder.OwnsMany(x => x.Lines, line =>
{
line.WithOwner().HasForeignKey("JournalEntryId");
line.Property<int>("Id").ValueGeneratedOnAdd();
line.HasKey("Id");
line.Property(x => x.Type).HasConversion<string>();
});
});
}
}