SnsDisconnect.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 SnsDisconnect : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapDelete("api/mypage/sns/{provider}", async (
  11. string provider,
  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. // path parameter 정규화 — google → Google
  22. var normalizedProvider = char.ToUpperInvariant(provider[0]) + provider[1..].ToLowerInvariant();
  23. var command = new Application.Features.Api.MyPage.Sns.Disconnect.Command(
  24. memberID.Value,
  25. normalizedProvider
  26. );
  27. var result = await sender.Send(command, ct);
  28. return result.Match(
  29. data => ApiResponse.Ok(data),
  30. CustomResults.Problem
  31. );
  32. })
  33. .WithTags("MyPage")
  34. .RequireAuthorization();
  35. }
  36. }