Send.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.Forum.PostCheer;
  6. // 분석글 응원(Cheer) 발신 — D3 M4. 인증 필요. 본인 글 응원 금지·최소금액·일일 캡은 핸들러에서 검증.
  7. internal sealed class Send : IEndpoint
  8. {
  9. public sealed record Request(
  10. int Amount,
  11. string? Message
  12. );
  13. public void MapEndpoint(IEndpointRouteBuilder app)
  14. {
  15. app.MapPost("api/posts/{postID}/cheers", async (
  16. int postID,
  17. ClaimsPrincipal user,
  18. Request request,
  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.Forum.PostCheer.Send.Command(
  28. memberID.Value,
  29. postID,
  30. request.Amount,
  31. request.Message
  32. );
  33. var result = await sender.Send(command, ct);
  34. return result.Match(
  35. cheerID => ApiResponse.Ok(new { cheerID }),
  36. CustomResults.Problem
  37. );
  38. })
  39. .WithTags("Forum")
  40. .RequireAuthorization();
  41. }
  42. }