Article.cs 669 B

123456789101112131415161718192021222324252627
  1. using MediatR;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.News;
  5. internal sealed class Article : IEndpoint
  6. {
  7. public void MapEndpoint(IEndpointRouteBuilder app)
  8. {
  9. app.MapGet("api/news/articles/{id}", async (
  10. int id,
  11. ISender sender,
  12. CancellationToken ct
  13. ) =>
  14. {
  15. var result = await sender.Send(new Application.Features.Api.News.GetArticle.Query(id), ct);
  16. return result.Match(
  17. data => ApiResponse.Ok(data),
  18. CustomResults.Problem
  19. );
  20. })
  21. .WithTags("News")
  22. .AllowAnonymous();
  23. }
  24. }