DeleteSummary.cs 972 B

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