OrdersPlace.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Security.Claims;
  2. using System.Text.Json.Serialization;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. using Application.Abstractions.Messaging;
  6. namespace Web.Api.Endpoints.Store;
  7. public sealed class PlaceOrderRequest
  8. {
  9. [JsonPropertyName("channelID")]
  10. public int? ChannelID { get; set; }
  11. [JsonPropertyName("items")]
  12. public List<PlaceOrderItem> Items { get; set; } = [];
  13. public sealed class PlaceOrderItem
  14. {
  15. [JsonPropertyName("productID")]
  16. public int ProductID { get; set; }
  17. [JsonPropertyName("quantity")]
  18. public int Quantity { get; set; }
  19. }
  20. }
  21. /// <summary>상점 — 주문 결제 (PgCharged 차감 + 채널 보상 + 게임사 정산 큐).</summary>
  22. internal sealed class OrdersPlace : IEndpoint
  23. {
  24. public void MapEndpoint(IEndpointRouteBuilder app)
  25. {
  26. app.MapPost("api/store/orders", async (
  27. PlaceOrderRequest body,
  28. ClaimsPrincipal user,
  29. ISender sender,
  30. CancellationToken ct
  31. ) => {
  32. var memberID = user.GetRequiredMemberID();
  33. var items = body.Items.Select(i =>
  34. new Application.Features.Api.Store.Orders.Place.Command.Item(i.ProductID, i.Quantity)
  35. ).ToList();
  36. var result = await sender.Send(new Application.Features.Api.Store.Orders.Place.Command(
  37. memberID,
  38. body.ChannelID,
  39. items
  40. ), ct);
  41. if (result.IsFailure)
  42. {
  43. return CustomResults.Problem(result);
  44. }
  45. return ApiResponse.Ok(result.Value);
  46. })
  47. .WithTags("Store")
  48. .RequireAuthorization();
  49. }
  50. }