| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- using System.Security.Claims;
- using Application.Abstractions.Messaging;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.Feed;
- internal sealed class Update : IEndpoint
- {
- public sealed class Request
- {
- public string Content { get; set; } = "";
- public List<string>? Tags { get; set; }
- }
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapPut("api/feed/post/{postID:int}", async (
- int postID,
- Request request,
- 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.Update.Command(
- postID,
- memberID.Value,
- request.Content,
- request.Tags
- );
- var result = await sender.Send(command, ct);
- return result.Match(() => ApiResponse.Ok(true), CustomResults.Problem);
- })
- .WithTags("Feed")
- .RequireAuthorization();
- }
- }
|