feat: add Plaid transaction handling and async queue processing
- introduced new migration to add Cursor column to AccountMetadata. - updated AppDbContext model snapshot to reflect changes in the database schema. - implemented async queue processing with ChannelAsyncQueue and AsyncQueueHostedService. - created Plaid transaction handlers for added, modified, and removed transactions. - developed PlaidTransactionService and PlaidTransactionSyncer for syncing transactions. - added SyncUpdatesProcessor to handle sync updates from Plaid. - updated tests to accommodate changes in institution and account metadata handling.
This commit is contained in:
@@ -47,6 +47,52 @@ internal sealed class App(
|
||||
var keyRingEntry = await keyRing.SaveKeyAsync(key);
|
||||
_console.MarkupLine($"Key generated with id [green]{keyRingEntry.KeyId}[/] generated successfully.");
|
||||
break;
|
||||
case Commands.RemoveInstitution:
|
||||
var institutionId = await _console.AskAsync<string>("Enter the [green]institution id[/] of the item you want to remove:", cancellationToken);
|
||||
|
||||
var institution = await appDbContext.Institutions
|
||||
.Include(i => i.User)
|
||||
.Include(i => i.Metadata)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (institution is null)
|
||||
{
|
||||
_console.MarkupLine($"Institution with id [green]{institutionId}[/] not found.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (institution.User is null)
|
||||
{
|
||||
_console.MarkupLine($"Institution with id [green]{institutionId}[/] has no user.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (institution.Metadata is not PlaidInstitutionMetadata plaidInstitutionMetadata)
|
||||
{
|
||||
_console.MarkupLine($"Institution with id [green]{institutionId}[/] has no plaid metadata.");
|
||||
break;
|
||||
}
|
||||
|
||||
var accessToken = await encryptor.DecryptAsyncFor(institution.User, plaidInstitutionMetadata.EncryptedAccessToken, cancellationToken);
|
||||
|
||||
var plaidClient = scope.ServiceProvider.GetRequiredService<PlaidClient>();
|
||||
|
||||
var removeItemResponse = await plaidClient.ItemRemoveAsync(new()
|
||||
{
|
||||
AccessToken = accessToken,
|
||||
});
|
||||
|
||||
if (removeItemResponse.IsSuccessStatusCode is false)
|
||||
{
|
||||
_console.MarkupLine($"Failed to remove item for institution id [green]{institutionId}[/]. Plaid error: {removeItemResponse.Error?.ErrorMessage}");
|
||||
break;
|
||||
}
|
||||
|
||||
appDbContext.Institutions.Remove(institution);
|
||||
await appDbContext.SaveChangesAsync(cancellationToken);
|
||||
|
||||
_console.MarkupLine($"Institution with id [green]{institutionId}[/] removed successfully.");
|
||||
break;
|
||||
case Commands.Exit:
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user