History.cs 995 B

12345678910111213141516171819202122232425262728293031
  1. using Application.Abstractions.Messaging;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.Stocks;
  5. /// <summary>일별 시세 히스토리 — 페이징 + 기간(from/to) 필터 (익명 열람)</summary>
  6. internal sealed class History : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapGet("api/stocks/{code:regex(^\\d{{6}}$)}/history", async (
  11. string code,
  12. ISender sender,
  13. int page = 1,
  14. ushort perPage = 30,
  15. DateOnly? from = null,
  16. DateOnly? to = null,
  17. CancellationToken ct = default
  18. ) => {
  19. var result = await sender.Send(new Application.Features.Api.Stocks.GetHistory.Query(code, page, perPage, from, to), ct);
  20. return result.Match(
  21. () => ApiResponse.Ok(result.Value),
  22. CustomResults.Problem
  23. );
  24. })
  25. .WithTags("Stocks")
  26. .AllowAnonymous();
  27. }
  28. }