ChargeLogs.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.Security.Claims;
  2. using Application.Common;
  3. using MediatR;
  4. using Web.Api.Common;
  5. using Web.Api.Extensions;
  6. namespace Web.Api.Endpoints.MyPage;
  7. /// <summary>충전 내역 조회</summary>
  8. internal sealed class ChargeLogs : IEndpoint
  9. {
  10. public void MapEndpoint(IEndpointRouteBuilder app)
  11. {
  12. /// 기간별 충전 완료 내역 (today/week/month/quarter/half, 페이징)
  13. app.MapGet("api/mypage/charge-logs", async (
  14. string? type,
  15. int? page,
  16. int? perPage,
  17. ClaimsPrincipal user,
  18. ISender sender,
  19. CancellationToken ct
  20. ) => {
  21. var memberID = user.GetRequiredMemberID();
  22. var searchType = type ?? SearchDateType.Today;
  23. if (!SearchDateType.ValidTypes.Contains(searchType))
  24. {
  25. return ApiResponse.Fail(StatusCodes.Status400BadRequest, "Invalid type");
  26. }
  27. var query = new Application.Features.Api.MyPage.ChargeLogs.Query(
  28. memberID,
  29. searchType,
  30. page ?? 1,
  31. perPage ?? 20
  32. );
  33. var result = await sender.Send(query, ct);
  34. return result.Match(
  35. data => ApiResponse.Ok(data),
  36. CustomResults.Problem
  37. );
  38. })
  39. .WithTags("MyPage")
  40. .RequireAuthorization();
  41. }
  42. }