Handler.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Application.Abstractions.Data;
  2. using Domain.Entities.Wallets.ValueObject;
  3. using MediatR;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Member.Wallet.Transactions.Get;
  6. public sealed class Handler(IAppDbContext db) : IRequestHandler<Query, Response>
  7. {
  8. public async Task<Response> Handle(Query request, CancellationToken ct)
  9. {
  10. var tx = await db.WalletTransaction.AsNoTracking().Include(x => x.Wallet).ThenInclude(w => w.Member).Include(x => x.Wallet).ThenInclude(w => w.Balances).FirstOrDefaultAsync(x => x.ID == request.Id, ct);
  11. if (tx is null) throw new KeyNotFoundException("거래 내역을 찾을 수 없습니다.");
  12. var wallet = tx.Wallet;
  13. return new Response
  14. {
  15. ID = tx.ID,
  16. WalletKey = tx.WalletKey,
  17. WalletID = wallet.ID,
  18. MemberID = wallet.MemberID,
  19. MemberEmail = wallet.Member.Email,
  20. MemberName = wallet.Member.Name,
  21. WalletBalance = (long)wallet.GetTotalAvailable().Value,
  22. WalletDonationBalance = (long)wallet.GetBalance(WalletBalanceType.Donation).Value,
  23. TxType = tx.TxType,
  24. BalanceType = tx.BalanceType,
  25. Amount = (long)tx.Amount.Value,
  26. BalanceAfter = (long)tx.BalanceAfter.Value,
  27. Reason = tx.Reason,
  28. RefID = tx.RefID,
  29. UserID = tx.UserID,
  30. Memo = tx.Memo,
  31. CreatedAt = tx.CreatedAt
  32. };
  33. }
  34. }