using System.Security.Claims; using Application.Abstractions.Messaging; using Web.Api.Common; using Web.Api.Extensions; namespace Web.Api.Endpoints.Member.Follow; internal sealed class Toggle : IEndpoint { public void MapEndpoint(IEndpointRouteBuilder app) { app.MapPost("api/member/{memberSID}/follow", async ( string memberSID, ClaimsPrincipal user, ISender sender, CancellationToken ct ) => { var memberID = user.GetMemberID(); if (memberID is null) { return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token"); } var command = new Application.Features.Api.Member.Follow.Toggle.Command(memberID.Value, memberSID); var result = await sender.Send(command, ct); return result.Match( data => ApiResponse.Ok(data), CustomResults.Problem ); }) .WithTags("Member.Follow") .RequireAuthorization(); } }