Handler.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Domain.Entities.Wallets.ValueObject;
  4. using Microsoft.EntityFrameworkCore;
  5. namespace Application.Features.Admin.Member.Wallet.Transactions.Get;
  6. public sealed class Handler(IAppDbContext db) : IQueryHandler<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)
  12. {
  13. throw new KeyNotFoundException("거래 내역을 찾을 수 없습니다.");
  14. }
  15. var wallet = tx.Wallet;
  16. return new Response
  17. {
  18. ID = tx.ID,
  19. WalletKey = tx.WalletKey,
  20. WalletID = wallet.ID,
  21. MemberID = wallet.MemberID,
  22. MemberEmail = wallet.Member.Email,
  23. MemberName = wallet.Member.Name,
  24. WalletBalance = (long)wallet.GetTotalAvailable().Value,
  25. WalletDonationBalance = (long)wallet.GetBalance(WalletBalanceType.Donation).Value,
  26. TxType = tx.TxType,
  27. BalanceType = tx.BalanceType,
  28. Amount = (long)tx.Amount.Value,
  29. BalanceAfter = (long)tx.BalanceAfter.Value,
  30. Reason = tx.Reason,
  31. RefID = tx.RefID,
  32. UserID = tx.UserID,
  33. Memo = tx.Memo,
  34. CreatedAt = tx.CreatedAt
  35. };
  36. }
  37. }