Update.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Security.Claims;
  2. using Application.Abstractions.Messaging;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.Feed;
  6. internal sealed class Update : IEndpoint
  7. {
  8. public sealed class Request
  9. {
  10. public string Content { get; set; } = "";
  11. public List<string>? Tags { get; set; }
  12. }
  13. public void MapEndpoint(IEndpointRouteBuilder app)
  14. {
  15. app.MapPut("api/feed/post/{postID:int}", async (
  16. int postID,
  17. Request request,
  18. ClaimsPrincipal user,
  19. ISender sender,
  20. CancellationToken ct
  21. ) => {
  22. var memberID = user.GetMemberID();
  23. if (memberID is null)
  24. {
  25. return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
  26. }
  27. var command = new Application.Features.Api.Feed.Update.Command(
  28. postID,
  29. memberID.Value,
  30. request.Content,
  31. request.Tags
  32. );
  33. var result = await sender.Send(command, ct);
  34. return result.Match(() => ApiResponse.Ok(true), CustomResults.Problem);
  35. })
  36. .WithTags("Feed")
  37. .RequireAuthorization();
  38. }
  39. }