29 lines
875 B
C#
29 lines
875 B
C#
using FinancialApi.Application;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Wolverine.Attributes;
|
|
using Wolverine.Persistence;
|
|
|
|
namespace FinancialApi.Infrastructure;
|
|
|
|
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); |