Delete.cs 1001 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Security.Claims;
  2. using MediatR;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.Forum.Comment;
  6. internal sealed class Delete : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapDelete("api/forum/comments/{id}", async (
  11. int id,
  12. ClaimsPrincipal user,
  13. ISender sender,
  14. CancellationToken ct
  15. ) => {
  16. var memberID = user.GetMemberID();
  17. if (memberID is null)
  18. {
  19. return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
  20. }
  21. var command = new Application.Features.Api.Forum.Comment.Delete.Command(id, memberID.Value);
  22. var result = await sender.Send(command, ct);
  23. return result.Match(
  24. () => ApiResponse.Ok(),
  25. CustomResults.Problem
  26. );
  27. })
  28. .WithTags("Forum")
  29. .RequireAuthorization();
  30. }
  31. }