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