| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- using System.Security.Claims;
- using Application.Common;
- using MediatR;
- using Web.Api.Common;
- using Web.Api.Extensions;
- namespace Web.Api.Endpoints.MyPage;
- internal sealed class GetLoginLogs : IEndpoint
- {
- public void MapEndpoint(IEndpointRouteBuilder app)
- {
- app.MapGet("api/mypage/login-logs", async (
- string? type,
- int? page,
- int? perPage,
- ClaimsPrincipal user,
- ISender sender,
- CancellationToken ct
- ) => {
- var memberID = user.GetMemberID();
- if (memberID is null)
- {
- return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token");
- }
- var searchType = type ?? SearchDateType.Today;
- if (!SearchDateType.ValidTypes.Contains(searchType))
- {
- return ApiResponse.Fail(StatusCodes.Status400BadRequest, "Invalid type");
- }
- var query = new Application.Features.Api.MyPage.GetLoginLogs.Query(
- memberID.Value,
- searchType,
- page ?? 1,
- perPage ?? 20
- );
- var result = await sender.Send(query, ct);
- return result.Match(
- data => ApiResponse.Ok(data),
- CustomResults.Problem
- );
- })
- .WithTags("MyPage")
- .RequireAuthorization();
- }
- }
|