ChangeBanner.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Security.Claims;
  2. using Application.Abstractions.Messaging;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.MyPage;
  6. internal sealed class ChangeBanner : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/mypage/banner", async (
  11. IFormFile? banner,
  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.ChangeBanner.Command(memberID.Value, banner);
  22. var result = await sender.Send(command, ct);
  23. return result.Match(
  24. data => ApiResponse.Ok(new { bannerUrl = data }),
  25. CustomResults.Problem
  26. );
  27. })
  28. .WithTags("MyPage")
  29. .RequireAuthorization()
  30. .DisableAntiforgery();
  31. }
  32. }