Handler.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. .FirstOrDefaultAsync(c => c.ID == request.ID, ct);
  14. if (coin is null)
  15. {
  16. throw new KeyNotFoundException("코인을 찾을 수 없습니다.");
  17. }
  18. return new Response(
  19. coin.ID,
  20. coin.Symbol,
  21. coin.KorName,
  22. coin.EngName,
  23. coin.LogoImage,
  24. coin.Description,
  25. coin.ContractAddress,
  26. coin.WebsiteUrl,
  27. coin.WhitepaperUrl,
  28. coin.TwitterUrl,
  29. coin.TelegramUrl,
  30. coin.IsActive,
  31. coin.IsWarning,
  32. coin.IsNew,
  33. coin.IsDelisted,
  34. [..coin.CoinCategoryMap.Select(m => m.CategoryID)],
  35. coin.UpdatedAt,
  36. coin.CreatedAt
  37. );
  38. }
  39. }
  40. }