OrdersPlace.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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("giftToMemberID")]
  12. public int? GiftToMemberID { get; set; }
  13. [JsonPropertyName("giftMessage")]
  14. public string? GiftMessage { get; set; }
  15. [JsonPropertyName("items")]
  16. public List<PlaceOrderItem> Items { get; set; } = [];
  17. public sealed class PlaceOrderItem
  18. {
  19. [JsonPropertyName("productID")]
  20. public int ProductID { get; set; }
  21. [JsonPropertyName("quantity")]
  22. public int Quantity { get; set; }
  23. }
  24. }
  25. /// <summary>상점 — 주문 결제 (PgCharged 차감 + 채널 보상 + 게임사 정산 큐).</summary>
  26. internal sealed class OrdersPlace : IEndpoint
  27. {
  28. public void MapEndpoint(IEndpointRouteBuilder app)
  29. {
  30. app.MapPost("api/store/orders", async (
  31. PlaceOrderRequest body,
  32. ClaimsPrincipal user,
  33. ISender sender,
  34. CancellationToken ct
  35. ) => {
  36. var memberID = user.GetRequiredMemberID();
  37. var items = body.Items.Select(i =>
  38. new Application.Features.Api.Store.Orders.Place.Command.Item(i.ProductID, i.Quantity)
  39. ).ToList();
  40. var result = await sender.Send(new Application.Features.Api.Store.Orders.Place.Command(
  41. memberID,
  42. body.ChannelID,
  43. items,
  44. body.GiftToMemberID,
  45. body.GiftMessage
  46. ), ct);
  47. if (result.IsFailure)
  48. {
  49. return CustomResults.Problem(result);
  50. }
  51. return ApiResponse.Ok(result.Value);
  52. })
  53. .WithTags("Store")
  54. .RequireAuthorization();
  55. }
  56. }