feat: implement transaction handling and add integration tests for Plaid transaction handlers
This commit is contained in:
@@ -2,13 +2,13 @@ namespace FiscalOS.Core.Transactions;
|
||||
|
||||
public sealed class Transaction : Entity
|
||||
{
|
||||
public Guid UserId { get; init; }
|
||||
public Guid UserId { get; private set; }
|
||||
public User? User { get; init; }
|
||||
|
||||
public Guid AccountId { get; init; }
|
||||
public Account? Account { get; init; }
|
||||
|
||||
public string MerchantName { get; init; } = string.Empty;
|
||||
public string MerchantName { get; private set; } = string.Empty;
|
||||
public string Description { get; init; } = string.Empty;
|
||||
public decimal Amount { get; init; }
|
||||
public DateTimeOffset Date { get; init; }
|
||||
@@ -27,7 +27,7 @@ public sealed class Transaction : Entity
|
||||
TransactionMetadata metadata
|
||||
)
|
||||
{
|
||||
return From(Guid.Empty, Guid.Empty, merchantName, description, amount, date, metadata);
|
||||
return From(Guid.Empty, Guid.Empty, Guid.Empty, merchantName, description, amount, date, metadata);
|
||||
}
|
||||
|
||||
public static Transaction From(
|
||||
@@ -39,6 +39,20 @@ public sealed class Transaction : Entity
|
||||
DateTimeOffset? date,
|
||||
TransactionMetadata metadata
|
||||
)
|
||||
{
|
||||
return From(Guid.Empty, userId, accountId, merchantName, description, amount, date, metadata);
|
||||
}
|
||||
|
||||
public static Transaction From(
|
||||
Guid id,
|
||||
Guid userId,
|
||||
Guid accountId,
|
||||
string merchantName,
|
||||
string description,
|
||||
decimal? amount,
|
||||
DateTimeOffset? date,
|
||||
TransactionMetadata metadata
|
||||
)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(merchantName, nameof(merchantName));
|
||||
ArgumentNullException.ThrowIfNull(description, nameof(description));
|
||||
@@ -55,6 +69,7 @@ public sealed class Transaction : Entity
|
||||
|
||||
return new()
|
||||
{
|
||||
Id = id,
|
||||
UserId = userId,
|
||||
AccountId = accountId,
|
||||
MerchantName = merchantName,
|
||||
|
||||
@@ -26,6 +26,14 @@ internal sealed class PlaidAddedTransactionHandler : IPlaidAddedTransactionHandl
|
||||
_appDbContext = appDbContext;
|
||||
}
|
||||
|
||||
public static PlaidAddedTransactionHandler From(
|
||||
ILogger<PlaidAddedTransactionHandler> logger,
|
||||
AppDbContext appDbContext
|
||||
)
|
||||
{
|
||||
return new(logger, appDbContext);
|
||||
}
|
||||
|
||||
public static PlaidAddedTransactionHandler From(IServiceProvider serviceProvider)
|
||||
{
|
||||
return new(
|
||||
|
||||
@@ -26,6 +26,14 @@ internal sealed class PlaidModifiedTransactionHandler : IPlaidModifiedTransactio
|
||||
_appDbContext = appDbContext;
|
||||
}
|
||||
|
||||
public static PlaidModifiedTransactionHandler From(
|
||||
ILogger<PlaidModifiedTransactionHandler> logger,
|
||||
AppDbContext appDbContext
|
||||
)
|
||||
{
|
||||
return new(logger, appDbContext);
|
||||
}
|
||||
|
||||
public static PlaidModifiedTransactionHandler From(IServiceProvider serviceProvider)
|
||||
{
|
||||
return new(
|
||||
@@ -71,6 +79,7 @@ internal sealed class PlaidModifiedTransactionHandler : IPlaidModifiedTransactio
|
||||
}
|
||||
|
||||
var newTransactionData = Transaction.From(
|
||||
existing.Id,
|
||||
existing.UserId,
|
||||
existing.AccountId,
|
||||
plaidModifiedTransaction.Merchant,
|
||||
|
||||
@@ -28,6 +28,15 @@ internal sealed class PlaidTransactionProcessor : IPlaidTransactionProcessor
|
||||
_removedHandler = removedHandler;
|
||||
}
|
||||
|
||||
internal static PlaidTransactionProcessor From(
|
||||
IPlaidAddedTransactionHandler addedHandler,
|
||||
IPlaidModifiedTransactionHandler modifiedHandler,
|
||||
IPlaidRemovedTransactionHandler removedHandler
|
||||
)
|
||||
{
|
||||
return new(addedHandler, modifiedHandler, removedHandler);
|
||||
}
|
||||
|
||||
internal static PlaidTransactionProcessor From(IServiceProvider provider)
|
||||
{
|
||||
return new(
|
||||
|
||||
@@ -28,6 +28,15 @@ internal sealed class PlaidTransactionSyncer : IPlaidTransactionSyncer
|
||||
_transactionProcessor = plaidTransactionProcessor;
|
||||
}
|
||||
|
||||
public static PlaidTransactionSyncer From(
|
||||
ILogger<PlaidTransactionSyncer> logger,
|
||||
IPlaidTransactionService plaidTransactionService,
|
||||
IPlaidTransactionProcessor plaidTransactionProcessor
|
||||
)
|
||||
{
|
||||
return new(logger, plaidTransactionService, plaidTransactionProcessor);
|
||||
}
|
||||
|
||||
public static PlaidTransactionSyncer From(IServiceProvider serviceProvider)
|
||||
{
|
||||
return new(
|
||||
|
||||
Reference in New Issue
Block a user