ChangeThumb.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 ChangeThumb : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/mypage/thumb", async (
  11. IFormFile? thumb,
  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.MyPage.ChangeThumb.Command(
  22. memberID.Value,
  23. thumb
  24. );
  25. var result = await sender.Send(command, ct);
  26. return result.Match(
  27. data => ApiResponse.Ok(new { thumbUrl = data }),
  28. CustomResults.Problem
  29. );
  30. })
  31. .WithTags("MyPage")
  32. .RequireAuthorization()
  33. .DisableAntiforgery();
  34. }
  35. }