using System.Security.Claims; using MediatR; using Web.Api.Common; using Web.Api.Extensions; namespace Web.Api.Endpoints.ChannelTitle; internal sealed class DeleteChannelTitle : IEndpoint { public void MapEndpoint(IEndpointRouteBuilder app) { app.MapDelete("api/channel-titles/{titleID:int}", async ( int titleID, 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.ChannelTitle.DeleteChannelTitle.Command(memberID.Value, titleID); var result = await sender.Send(command, ct); return result.Match( () => ApiResponse.Ok(), CustomResults.Problem ); }) .WithTags("ChannelTitle") .RequireAuthorization(); } }