Skip to content

Commit

Permalink
Merge pull request #24 from Star-Academy/bugfix/fix-uploads
Browse files Browse the repository at this point in the history
fix: fix upload bugs on adding existing files
  • Loading branch information
mobinbr authored Aug 27, 2024
2 parents b9591c1 + d88391b commit ca3166a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface IAccountRepository
Task CreateBulkAsync(List<Account> accounts);
Task<Account?> GetByIdAsync(long accountId);
Task<List<Account>> GetAllAccounts();
Task<List<long>> GetAllIdsAsync();
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface ITransactionRepository
Task<List<Transaction>> GetAllTransactions();
Task<List<Transaction>> GetBySourceAccountId(long accountId);
Task<List<Transaction>> GetByDestinationAccountId(long accountId);
Task<List<long>> GetAllIdsAsync();
}
5 changes: 4 additions & 1 deletion src/Application/Services/DomainService/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public async Task<Result> AddAccountsFromCsvAsync(string filePath)
.ToList();
try
{
await _accountRepository.CreateBulkAsync(accounts);
var existingAccountIds = await _accountRepository.GetAllIdsAsync();
var newAccounts = accounts.Where(a => !existingAccountIds.Contains(a.AccountId)).ToList();

await _accountRepository.CreateBulkAsync(newAccounts);
return Result.Ok();
}
catch (Exception ex)
Expand Down
5 changes: 4 additions & 1 deletion src/Application/Services/DomainService/TransactionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ public async Task<Result> AddTransactionsFromCsvAsync(string filePath)

try
{
await _transactionRepository.CreateBulkAsync(transactions);
var existingTransactionsIds = await _transactionRepository.GetAllIdsAsync();
var newTransactions = transactions.Where(t => !existingTransactionsIds.Contains(t.TransactionId)).ToList();

await _transactionRepository.CreateBulkAsync(newTransactions);
return Result.Ok();
}
catch (Exception ex)
Expand Down
7 changes: 7 additions & 0 deletions src/Infrastructure/Repositories/AccountRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,11 @@ public async Task<List<Account>> GetAllAccounts()
{
return await _dbContext.Accounts.ToListAsync();
}

public async Task<List<long>> GetAllIdsAsync()
{
return await _dbContext.Accounts
.Select(a => a.AccountId)
.ToListAsync();
}
}
7 changes: 7 additions & 0 deletions src/Infrastructure/Repositories/TransactionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,11 @@ public Task<List<Transaction>> GetByDestinationAccountId(long accountId)
.Where(transaction => transaction.DestinationAccountId == accountId)
.ToListAsync();
}

public async Task<List<long>> GetAllIdsAsync()
{
return await _dbContext.Transactions
.Select(a => a.TransactionId)
.ToListAsync();
}
}

0 comments on commit ca3166a

Please sign in to comment.