| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using Application.Abstractions.Messaging;
- using Application.Features.Api.Forum.StockBoard.CreatePost;
- using Web.Api.Common;
- using Web.Api.Extensions;
- using Microsoft.AspNetCore.Mvc;
- using System.Security.Claims;
- namespace Web.Api.Endpoints.Forum.StockBoard;
- /// <summary>종목 가상보드 글 작성 — POST /api/boards/stock/posts (JWT). 예측(선택) 동시 등록.</summary>
- internal sealed class CreatePost : IEndpoint
- {
- public sealed class PredictionBody
- {
- public byte Direction { get; set; }
- public short HorizonDays { get; set; }
- public decimal? TargetPrice { get; set; }
- }
- public sealed class Request
- {
- public string StockCode { get; set; } = "";
- public string Subject { get; set; } = "";
- public string Content { get; set; } = "";
- public PredictionBody? Prediction { get; set; }
- }
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapPost("api/boards/stock/posts", async (
- ClaimsPrincipal user,
- [FromBody] Request request,
- ISender sender,
- CancellationToken ct
- ) => {
- var memberID = user.GetMemberID();
- if (memberID is null)
- {
- return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
- }
- var prediction = request.Prediction is { } p
- ? new PredictionInput(p.Direction, p.HorizonDays, p.TargetPrice)
- : null;
- var command = new Command(memberID.Value, request.StockCode, request.Subject, request.Content, prediction);
- var result = await sender.Send(command, ct);
- return result.Match(
- postID => ApiResponse.Created(new { ID = postID }),
- CustomResults.Problem
- );
- })
- .WithTags("StockBoard")
- .RequireAuthorization();
- }
- }
|