PlaceOrder.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System.Security.Claims;
  2. using System.Text.Json.Serialization;
  3. using Application.Abstractions.Messaging;
  4. using Domain.Entities.Paper.ValueObject;
  5. using Web.Api.Common;
  6. using Web.Api.Extensions;
  7. namespace Web.Api.Endpoints.Paper;
  8. public sealed class PlaceOrderRequest
  9. {
  10. [JsonPropertyName("stockCode")]
  11. public string StockCode { get; set; } = "";
  12. [JsonPropertyName("side")]
  13. public PaperOrderSide Side { get; set; }
  14. [JsonPropertyName("quantity")]
  15. public int Quantity { get; set; }
  16. }
  17. /// <summary>모의투자 — 주문 접수.</summary>
  18. internal sealed class PlaceOrder : IEndpoint
  19. {
  20. public void MapEndpoint(IEndpointRouteBuilder app)
  21. {
  22. app.MapPost("api/paper/orders", async (
  23. PlaceOrderRequest body,
  24. ClaimsPrincipal user,
  25. ISender sender,
  26. CancellationToken ct
  27. ) => {
  28. var memberID = user.GetRequiredMemberID();
  29. var result = await sender.Send(new Application.Features.Api.Paper.PlaceOrder.Command(memberID, body.StockCode, body.Side, body.Quantity), ct);
  30. if (result.IsFailure)
  31. {
  32. return CustomResults.Problem(result);
  33. }
  34. return ApiResponse.Ok(result.Value);
  35. })
  36. .WithTags("Paper")
  37. .RequireAuthorization();
  38. }
  39. }