feat(usability): explain booking fields and validate decimal input (U06)
This commit is contained in:
@@ -99,6 +99,8 @@ public class EntryService : IEntryService
|
||||
|
||||
public async Task<EntryDto> CreateEntryAsync(int accountId, EntryType type, DateTime date, string title, decimal amount)
|
||||
{
|
||||
if (!Enum.IsDefined(type)) throw new ArgumentException("Ungültige Buchungsart.");
|
||||
BookingInput.Validate(date, title, amount);
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
@@ -110,7 +112,7 @@ public class EntryService : IEntryService
|
||||
DisplayId = displayId,
|
||||
Type = type,
|
||||
Date = date,
|
||||
Title = title,
|
||||
Title = title.Trim(),
|
||||
Amount = amount
|
||||
};
|
||||
db.Entries.Add(entry);
|
||||
@@ -121,6 +123,7 @@ public class EntryService : IEntryService
|
||||
|
||||
public async Task CreateTransferAsync(int sourceAccountId, int targetAccountId, DateTime date, string title, decimal amount)
|
||||
{
|
||||
BookingInput.Validate(date, title, amount);
|
||||
if (sourceAccountId == targetAccountId)
|
||||
throw new InvalidOperationException("Umbuchung innerhalb desselben Kontos ist nicht möglich.");
|
||||
|
||||
@@ -136,7 +139,7 @@ public class EntryService : IEntryService
|
||||
DisplayId = transferDisplayId,
|
||||
Type = EntryType.Expense,
|
||||
Date = date,
|
||||
Title = title,
|
||||
Title = title.Trim(),
|
||||
Amount = amount
|
||||
};
|
||||
|
||||
@@ -149,7 +152,7 @@ public class EntryService : IEntryService
|
||||
DisplayId = transferDisplayId,
|
||||
Type = EntryType.Income,
|
||||
Date = date,
|
||||
Title = title,
|
||||
Title = title.Trim(),
|
||||
Amount = amount
|
||||
};
|
||||
|
||||
@@ -220,6 +223,7 @@ public class EntryService : IEntryService
|
||||
|
||||
public async Task UpdateEntryAsync(int entryId, DateTime date, string title, decimal amount)
|
||||
{
|
||||
BookingInput.Validate(date, title, amount);
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
@@ -230,7 +234,7 @@ public class EntryService : IEntryService
|
||||
.FirstOrDefaultAsync(tl => tl.SourceEntryId == entryId || tl.TargetEntryId == entryId);
|
||||
|
||||
entry.Date = date;
|
||||
entry.Title = title;
|
||||
entry.Title = title.Trim();
|
||||
entry.Amount = amount;
|
||||
|
||||
if (link != null)
|
||||
@@ -240,7 +244,7 @@ public class EntryService : IEntryService
|
||||
if (otherEntry != null)
|
||||
{
|
||||
otherEntry.Date = date;
|
||||
otherEntry.Title = title;
|
||||
otherEntry.Title = title.Trim();
|
||||
otherEntry.Amount = amount;
|
||||
}
|
||||
}
|
||||
@@ -250,6 +254,7 @@ public class EntryService : IEntryService
|
||||
|
||||
public async Task UpdateTransferAsync(int entryId, int newLinkedAccountId, DateTime date, string title, decimal amount)
|
||||
{
|
||||
BookingInput.Validate(date, title, amount);
|
||||
using var lease = await DatabaseLease.AcquireAsync(_location);
|
||||
await using var db = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
@@ -266,10 +271,10 @@ public class EntryService : IEntryService
|
||||
|
||||
// Update date, title, amount on both sides
|
||||
entry.Date = date;
|
||||
entry.Title = title;
|
||||
entry.Title = title.Trim();
|
||||
entry.Amount = amount;
|
||||
otherEntry.Date = date;
|
||||
otherEntry.Title = title;
|
||||
otherEntry.Title = title.Trim();
|
||||
otherEntry.Amount = amount;
|
||||
|
||||
// If the linked account has changed, move the other entry to the new account
|
||||
|
||||
Reference in New Issue
Block a user