Handler.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Application.Abstractions.Messaging;
  2. using Application.Abstractions.Data;
  3. using Microsoft.EntityFrameworkCore;
  4. namespace Application.Features.Admin.Crypto.List.Get
  5. {
  6. public sealed class Handler(IAppDbContext db) : IQueryHandler<Query, Response>
  7. {
  8. public async Task<Response> Handle(Query request, CancellationToken ct)
  9. {
  10. var coin = await db.Coin
  11. .AsNoTracking()
  12. .Include(c => c.CoinCategoryMap)
  13. .Include(c => c.CoinMarket)
  14. .FirstOrDefaultAsync(c => c.ID == request.ID, ct);
  15. if (coin is null)
  16. {
  17. throw new KeyNotFoundException("코인을 찾을 수 없습니다.");
  18. }
  19. return new Response(
  20. coin.ID,
  21. coin.Symbol,
  22. [..coin.CoinMarket.Select(m => m.Market)],
  23. coin.KorName,
  24. coin.EngName,
  25. coin.LogoImage,
  26. coin.Description,
  27. coin.ContractAddress,
  28. coin.WebsiteUrl,
  29. coin.WhitepaperUrl,
  30. coin.TwitterUrl,
  31. coin.TelegramUrl,
  32. coin.IsActive,
  33. coin.IsWarning,
  34. coin.IsNew,
  35. coin.IsDelisted,
  36. [..coin.CoinCategoryMap.Select(m => m.CategoryID)],
  37. coin.UpdatedAt,
  38. coin.CreatedAt
  39. );
  40. }
  41. }
  42. }