Added a transfer funds handler using a-frame and wolverine.
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
using FinancialApi.Application;
|
||||
using FinancialApi.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Wolverine.Attributes;
|
||||
using Wolverine.Persistence;
|
||||
|
||||
namespace FinancialApi;
|
||||
|
||||
public static class ApplyFeeHandler
|
||||
{
|
||||
public static Task<Account?> LoadAsync(
|
||||
ApplyFeeCommand cmd,
|
||||
AccountDbContext db) => db.Accounts.AsNoTracking().SingleOrDefaultAsync(x => x.Id == cmd.AccountId);
|
||||
|
||||
[Transactional]
|
||||
public static (IStorageAction<Account> UpdatedAccount, FeeAppliedEvent Event) Handle(
|
||||
ApplyFeeCommand cmd,
|
||||
Account account)
|
||||
{
|
||||
var updatedAccount = account.ApplyFee(cmd.Amount);
|
||||
|
||||
var @event = new FeeAppliedEvent(account.Id, cmd.Amount);
|
||||
|
||||
return (Storage.Update(updatedAccount), @event);
|
||||
}
|
||||
}
|
||||
|
||||
public record ApplyFeeCommand(int AccountId, decimal Amount);
|
||||
|
||||
public record FeeAppliedEvent(int AccountId, decimal Amount);
|
||||
@@ -3,7 +3,7 @@
|
||||
GET {{FinancialApi_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
### Apply Fee to an Account
|
||||
|
||||
POST {{FinancialApi_HostAddress}}/accounts/apply-fee
|
||||
Accept: application/json
|
||||
@@ -14,4 +14,13 @@ Content-Type: application/json
|
||||
"amount": 5.0
|
||||
}
|
||||
|
||||
###
|
||||
### Transfer Between Accounts
|
||||
|
||||
POST {{FinancialApi_HostAddress}}/accounts/transfer
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"sourceAccountId": 1,
|
||||
"destinationAccountId": 2,
|
||||
"amount": 30.00
|
||||
}
|
||||
|
||||
@@ -53,4 +53,10 @@ app.MapPost("/accounts/apply-fee", async (ApplyFeeCommand cmd, IMessageBus bus)
|
||||
return Results.Accepted();
|
||||
});
|
||||
|
||||
app.MapPost("/accounts/transfer", async (TransferFundsCommand cmd, IMessageBus bus) =>
|
||||
{
|
||||
await bus.InvokeAsync(cmd);
|
||||
return Results.Accepted();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user