| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System.Security.Claims;
- using MediatR;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.Forum.Comment;
- internal sealed class Update : IEndpoint
- {
- public sealed record Request(
- string Content,
- bool IsSecret
- );
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapPut("api/forum/comments/{id}", async (
- int id,
- ClaimsPrincipal user,
- Request request,
- 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.Forum.Comment.Update.Command(
- id,
- memberID.Value,
- request.Content,
- request.IsSecret
- );
- var result = await sender.Send(command, ct);
- return result.Match(
- () => ApiResponse.Ok(),
- CustomResults.Problem
- );
- })
- .WithTags("Forum")
- .RequireAuthorization();
- }
- }
|