Refactor: use TransactionService for duplicate detection in Upload
Replace inline duplicate detection logic with TransactionService.IsDuplicateAsync(), consolidating duplicate checking into a single, testable service method. Removes duplicate IsDuplicate() method implementations from UploadModel. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -18,12 +18,14 @@ namespace MoneyMap.Pages
|
||||
private readonly MoneyMapContext _db;
|
||||
private readonly ITransactionImporter _importer;
|
||||
private readonly ITransactionCategorizer _categorizer;
|
||||
private readonly ITransactionService _transactionService;
|
||||
|
||||
public UploadModel(MoneyMapContext db, ITransactionImporter importer, ITransactionCategorizer categorizer)
|
||||
public UploadModel(MoneyMapContext db, ITransactionImporter importer, ITransactionCategorizer categorizer, ITransactionService transactionService)
|
||||
{
|
||||
_db = db;
|
||||
_importer = importer;
|
||||
_categorizer = categorizer;
|
||||
_transactionService = transactionService;
|
||||
}
|
||||
|
||||
[BindProperty] public IFormFile? Csv { get; set; }
|
||||
@@ -183,7 +185,7 @@ namespace MoneyMap.Pages
|
||||
}
|
||||
|
||||
// Check for duplicates
|
||||
if (!await IsDuplicate(txn))
|
||||
if (!await _transactionService.IsDuplicateAsync(txn))
|
||||
{
|
||||
transactionsToImport.Add(txn);
|
||||
}
|
||||
@@ -205,17 +207,6 @@ namespace MoneyMap.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
private async Task<bool> IsDuplicate(Transaction txn)
|
||||
{
|
||||
return await _db.Transactions.AnyAsync(t =>
|
||||
t.Date == txn.Date &&
|
||||
t.Amount == txn.Amount &&
|
||||
t.Name == txn.Name &&
|
||||
t.Memo == txn.Memo &&
|
||||
t.CardId == txn.CardId &&
|
||||
t.AccountId == txn.AccountId);
|
||||
}
|
||||
|
||||
private bool ValidateInput()
|
||||
{
|
||||
if (Csv is null || Csv.Length == 0)
|
||||
@@ -351,17 +342,6 @@ namespace MoneyMap.Pages
|
||||
return ImportOperationResult.Success(result);
|
||||
}
|
||||
|
||||
private async Task<bool> IsDuplicate(Transaction txn)
|
||||
{
|
||||
return await _db.Transactions.AnyAsync(t =>
|
||||
t.Date == txn.Date &&
|
||||
t.Amount == txn.Amount &&
|
||||
t.Name == txn.Name &&
|
||||
t.Memo == txn.Memo &&
|
||||
t.CardId == txn.CardId &&
|
||||
t.AccountId == txn.AccountId);
|
||||
}
|
||||
|
||||
private static Transaction MapToTransaction(TransactionCsvRow row, PaymentResolutionResult paymentResolution)
|
||||
{
|
||||
return new Transaction
|
||||
|
||||
Reference in New Issue
Block a user