From cedfe9878938c3d5fe17f056cdd7aa091b726c6e Mon Sep 17 00:00:00 2001 From: AJ Date: Sat, 25 Oct 2025 22:53:33 -0400 Subject: [PATCH] Refactor: use TransactionService for duplicate detection in Upload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- MoneyMap/Pages/Upload.cshtml.cs | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/MoneyMap/Pages/Upload.cshtml.cs b/MoneyMap/Pages/Upload.cshtml.cs index f3ea167..8cbedd7 100644 --- a/MoneyMap/Pages/Upload.cshtml.cs +++ b/MoneyMap/Pages/Upload.cshtml.cs @@ -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 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 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