CryptoTickers.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using MediatR;
  2. using Web.Api.Common;
  3. namespace Web.Api.Endpoints.Crypto;
  4. internal sealed class CryptoTickers : IEndpoint
  5. {
  6. public void MapEndpoint(IEndpointRouteBuilder app)
  7. {
  8. // 전체 코인 조회
  9. app.MapGet("api/crypto/tickers", async (
  10. string? quote,
  11. ISender sender,
  12. CancellationToken ct
  13. ) =>
  14. {
  15. var response = await sender.Send(new Application.Features.Api.Crypto.Ticker.GetAll.Query(quote), ct);
  16. return ApiResponse.Ok(response.Tickers);
  17. })
  18. .WithTags("Crypto")
  19. .AllowAnonymous();
  20. // 선별된 코인 조회
  21. app.MapGet("api/crypto/tickers/featured", async (
  22. string? quote,
  23. ISender sender,
  24. CancellationToken ct
  25. ) =>
  26. {
  27. var response = await sender.Send(new Application.Features.Api.Crypto.Ticker.GetAll.Query(quote, true), ct);
  28. return ApiResponse.Ok(response.Tickers);
  29. })
  30. .WithTags("Crypto")
  31. .AllowAnonymous();
  32. // 페어 단위 현재가 조회
  33. app.MapGet("api/crypto/{market}/ticker", async (
  34. string market,
  35. ISender sender,
  36. CancellationToken ct
  37. ) =>
  38. {
  39. return ApiResponse.Ok(
  40. await sender.Send(new Application.Features.Api.Crypto.Ticker.GetDetail.Query(NormalizeMarket(market)), ct)
  41. );
  42. })
  43. .WithTags("Crypto")
  44. .AllowAnonymous();
  45. }
  46. private static string NormalizeMarket(string input) =>
  47. input.Contains('-') ? input.ToUpper() : $"KRW-{input.ToUpper()}";
  48. }