CryptoTrades.cs 1011 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using MediatR;
  2. using Web.Api.Common;
  3. namespace Web.Api.Endpoints.Crypto;
  4. internal sealed class CryptoTrades : IEndpoint
  5. {
  6. public void MapEndpoint(IEndpointRouteBuilder app)
  7. {
  8. app.MapGet("api/crypto/{symbol}/trades", async (
  9. string symbol,
  10. int? count,
  11. ISender sender,
  12. CancellationToken ct
  13. ) =>
  14. {
  15. return ApiResponse.Ok(
  16. await sender.Send(new Application.Features.Api.Crypto.Trade.GetRecent.Query(symbol, count ?? 50), ct)
  17. );
  18. })
  19. .WithTags("Crypto")
  20. .AllowAnonymous();
  21. app.MapGet("api/crypto/{symbol}/trades/live", async (
  22. string symbol,
  23. ISender sender,
  24. CancellationToken ct
  25. ) =>
  26. {
  27. return ApiResponse.Ok(
  28. await sender.Send(new Application.Features.Api.Crypto.Trade.GetLive.Query(symbol), ct)
  29. );
  30. })
  31. .WithTags("Crypto")
  32. .AllowAnonymous();
  33. }
  34. }