Withdraw.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Security.Claims;
  2. using System.Text.Json.Serialization;
  3. using Application.Abstractions.Messaging;
  4. using Web.Api.Common;
  5. using Web.Api.Extensions;
  6. namespace Web.Api.Endpoints.Paper;
  7. public sealed class PaperWithdrawRequest
  8. {
  9. [JsonPropertyName("tokenAmount")]
  10. public decimal TokenAmount { get; set; }
  11. [JsonPropertyName("all")]
  12. public bool All { get; set; }
  13. }
  14. /// <summary>모의투자 — 출금 (계좌 → 지갑 토큰).</summary>
  15. internal sealed class Withdraw : IEndpoint
  16. {
  17. public void MapEndpoint(IEndpointRouteBuilder app)
  18. {
  19. app.MapPost("api/paper/account/withdraw", async (
  20. PaperWithdrawRequest body,
  21. ClaimsPrincipal user,
  22. ISender sender,
  23. CancellationToken ct
  24. ) => {
  25. var memberID = user.GetRequiredMemberID();
  26. var result = await sender.Send(new Application.Features.Api.Paper.Withdraw.Command(memberID, body.TokenAmount, body.All), ct);
  27. if (result.IsFailure)
  28. {
  29. return CustomResults.Problem(result);
  30. }
  31. return ApiResponse.Ok(result.Value);
  32. })
  33. .WithTags("Paper")
  34. .RequireAuthorization();
  35. }
  36. }