Refactor EntryService to allow shared DisplayId for transfers; update related tests and migration files

This commit is contained in:
2026-04-03 12:00:53 +02:00
parent 387c18e834
commit 69181e66b0
8 changed files with 365 additions and 14 deletions

View File

@@ -63,7 +63,7 @@ public class EntryService : IEntryService
{
await using var db = await _dbFactory.CreateDbContextAsync();
var displayId = await GenerateDisplayIdAsync(db, accountId, date.Year);
var displayId = await GenerateDisplayIdAsync(db, date.Year);
var entry = new Entry
{
@@ -88,12 +88,12 @@ public class EntryService : IEntryService
await using var db = await _dbFactory.CreateDbContextAsync();
await using var transaction = await db.Database.BeginTransactionAsync();
var sourceDisplayId = await GenerateDisplayIdAsync(db, sourceAccountId, date.Year);
var transferDisplayId = await GenerateDisplayIdAsync(db, date.Year);
var sourceEntry = new Entry
{
AccountId = sourceAccountId,
DisplayId = sourceDisplayId,
DisplayId = transferDisplayId,
Type = EntryType.Expense,
Date = date,
Title = title,
@@ -103,12 +103,10 @@ public class EntryService : IEntryService
db.Entries.Add(sourceEntry);
await db.SaveChangesAsync();
var targetDisplayId = await GenerateDisplayIdAsync(db, targetAccountId, date.Year);
var targetEntry = new Entry
{
AccountId = targetAccountId,
DisplayId = targetDisplayId,
DisplayId = transferDisplayId,
Type = EntryType.Income,
Date = date,
Title = title,
@@ -234,13 +232,12 @@ public class EntryService : IEntryService
if (otherEntry.AccountId != newLinkedAccountId)
{
otherEntry.AccountId = newLinkedAccountId;
otherEntry.DisplayId = await GenerateDisplayIdAsync(db, newLinkedAccountId, date.Year);
}
await db.SaveChangesAsync();
}
private static async Task<string> GenerateDisplayIdAsync(FinanceDbContext db, int accountId, int year)
private static async Task<string> GenerateDisplayIdAsync(FinanceDbContext db, int year)
{
var prefix = $"{year}-";
var maxDisplayId = await db.Entries