| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- using System.Security.Claims;
- using Application.Abstractions.Messaging;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.Forum.PostCheer;
- // 분석글 응원(Cheer) 발신 — D3 M4. 인증 필요. 본인 글 응원 금지·최소금액·일일 캡은 핸들러에서 검증.
- internal sealed class Send : IEndpoint
- {
- public sealed record Request(
- int Amount,
- string? Message
- );
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapPost("api/posts/{postID}/cheers", async (
- int postID,
- 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.PostCheer.Send.Command(
- memberID.Value,
- postID,
- request.Amount,
- request.Message
- );
- var result = await sender.Send(command, ct);
- return result.Match(
- cheerID => ApiResponse.Ok(new { cheerID }),
- CustomResults.Problem
- );
- })
- .WithTags("Forum")
- .RequireAuthorization();
- }
- }
|