List.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Security.Claims;
  2. using MediatR;
  3. using Web.Api.Common;
  4. using Web.Api.Extensions;
  5. namespace Web.Api.Endpoints.V1.Purchases;
  6. internal sealed class List : IEndpoint
  7. {
  8. public void MapEndpoint(IEndpointRouteBuilder app)
  9. {
  10. app.MapGet("v1/purchases", async (
  11. ClaimsPrincipal user,
  12. ISender sender,
  13. CancellationToken ct,
  14. string? status = null,
  15. DateTime? from = null,
  16. DateTime? to = null,
  17. int page = 1,
  18. int size = 50
  19. ) => {
  20. var query = new Application.Features.Api.V1.Purchases.List.Query(
  21. user.GetApplicationID(),
  22. user.GetPatOwnerMemberID(),
  23. status,
  24. from,
  25. to,
  26. page,
  27. size
  28. );
  29. var result = await sender.Send(query, ct);
  30. return result.Match(
  31. data => ApiResponse.Ok(data),
  32. CustomResults.Problem
  33. );
  34. })
  35. .WithTags("결제 보고")
  36. .WithGroupName("public")
  37. .WithName("ListPurchases")
  38. .WithSummary("결제 목록 조회")
  39. .WithDescription("""
  40. 등록한 결제 내역을 페이지네이션해 반환합니다 (정산 대사용).
  41. - OAuth2 앱 토큰: 해당 앱이 등록한 건만
  42. - PAT: 본인 소유 앱 전체
  43. ### 필수 scope
  44. - `read:purchases`
  45. ### 쿼리 파라미터
  46. | 이름 | 타입 | 기본 | 설명 |
  47. |---|---|---|---|
  48. | `status` | string? | 전체 | `pending` / `confirmed` / `canceled` |
  49. | `from` | datetime? | — | 등록 시각(UTC) 시작 |
  50. | `to` | datetime? | — | 등록 시각(UTC) 끝 |
  51. | `page` | int | 1 | 1부터 시작 |
  52. | `size` | int | 50 | 1~100 |
  53. ### 사용 예
  54. ```
  55. GET /v1/purchases?status=pending
  56. GET /v1/purchases?from=2026-06-01&to=2026-06-30&page=1&size=100
  57. ```
  58. """)
  59. .Produces<ApiResponse>(StatusCodes.Status200OK)
  60. .ProducesProblem(StatusCodes.Status400BadRequest)
  61. .ProducesProblem(StatusCodes.Status401Unauthorized)
  62. .ProducesProblem(StatusCodes.Status403Forbidden)
  63. .RequireAuthorization(policy => policy
  64. .AddAuthenticationSchemes("ApiKey", "OAuth2Bearer")
  65. .RequireAuthenticatedUser())
  66. .RequireScope("read:purchases");
  67. }
  68. }