ToggleLike.cs 991 B

123456789101112131415161718192021222324252627282930313233
  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 ToggleLike : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapPost("api/feed/post/{postID:int}/like", async (
  11. int postID,
  12. ClaimsPrincipal user,
  13. ISender sender,
  14. CancellationToken ct
  15. ) => {
  16. var memberID = user.GetMemberID();
  17. if (memberID is null)
  18. {
  19. return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
  20. }
  21. var command = new Application.Features.Api.Feed.ToggleLike.Command(postID, memberID.Value);
  22. var result = await sender.Send(command, ct);
  23. return result.Match(data => ApiResponse.Ok(data), CustomResults.Problem);
  24. })
  25. .WithTags("Feed")
  26. .RequireAuthorization();
  27. }
  28. }