List.cs 960 B

123456789101112131415161718192021222324252627282930313233343536
  1. using Web.Api.Common;
  2. using Web.Api.Extensions;
  3. using MediatR;
  4. using System.Security.Claims;
  5. namespace Web.Api.Endpoints.Forum.Comment;
  6. internal sealed class List : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapGet("api/forum/posts/{id}/comments", async (
  11. int id,
  12. ClaimsPrincipal user,
  13. ISender sender,
  14. CancellationToken ct,
  15. int page = 1,
  16. ushort perPage = 20,
  17. int sort = 0
  18. ) =>
  19. {
  20. var memberID = user.GetMemberID();
  21. var result = await sender.Send(
  22. new Application.Features.Api.Forum.Comment.List.Query(id, memberID, page, perPage, sort),
  23. ct
  24. );
  25. return result.Match(
  26. data => ApiResponse.Ok(data),
  27. CustomResults.Problem
  28. );
  29. })
  30. .WithTags("Forum")
  31. .AllowAnonymous();
  32. }
  33. }