Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {}
"tools": {
"dotnet-ef": {
"version": "10.0.1",
"commands": [
"dotnet-ef"
],
"rollForward": false
}
}
}
36 changes: 36 additions & 0 deletions PhantomDave.BankTracking.Api/Services/FileImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,30 @@ public IEnumerable<FinanceRecord> FromParsedData(int accountId, ParsedFileData p
record.Description = descriptionColumnValue;
}

if (input.ColumnMappings.TryGetValue("Name", out var nameColumn) && row.TryGetValue(nameColumn, out var nameColumnValue))
{
var trimmedName = nameColumnValue?.Trim() ?? string.Empty;
if (string.IsNullOrWhiteSpace(trimmedName))
{
record.Name = "Untitled";
}
else if (trimmedName.Length > 200)
{
_logger.LogWarning("Name value for row {RowIndex} exceeds 200 characters and will be truncated during import", records.Count + failedCount + 1);
record.Name = trimmedName.Substring(0, 200);
}
else
{
record.Name = trimmedName;
}
}

record.Currency = input.ColumnMappings.TryGetValue("Currency", out var currencyColumn)
&& row.TryGetValue(currencyColumn, out var currencyColumnValue)
&& !string.IsNullOrWhiteSpace(currencyColumnValue)
? NormalizeCurrency(currencyColumnValue)
: "USD";

record.AccountId = accountId;
record.Imported = true;

Expand All @@ -303,4 +327,16 @@ public IEnumerable<FinanceRecord> FromParsedData(int accountId, ParsedFileData p

return records;
}

private static string NormalizeCurrency(string currency)
{
var normalized = currency.Trim().ToUpperInvariant();

if (normalized.Length < 1 || normalized.Length > 3)
{
return "USD";
}

return normalized;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ private static void ConfigureFinanceRecord(ModelBuilder modelBuilder)
entity.Property(fr => fr.Id).ValueGeneratedOnAdd();
entity.Property(fr => fr.Amount)
.HasColumnType("numeric(18,2)");
entity.Property(fr => fr.Name)
.IsRequired()
.HasMaxLength(200)
.HasDefaultValue("Untitled");
entity.Property(fr => fr.Currency)
.IsRequired()
.HasMaxLength(3);
.HasMaxLength(3)
.HasDefaultValue("USD");
entity.Property(fr => fr.Description)
.HasMaxLength(500);
entity.HasOne<Account>()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading