using System.Security.Claims; using Domain.Entities.Donations.ValueObject; using MediatR; using Web.Api.Common; using Web.Api.Extensions; namespace Web.Api.Endpoints.Ranking; internal sealed class GetMyRank : IEndpoint { public void MapEndpoint(IEndpointRouteBuilder app) { app.MapGet("api/ranking/my-rank", async ( string? type, string? period, string? category, ClaimsPrincipal user, ISender sender, CancellationToken ct ) => { var memberID = user.GetMemberID(); if (memberID is null) { return ApiResponse.Fail(StatusCodes.Status401Unauthorized, "Invalid token"); } var rankingType = type?.ToLowerInvariant() switch { "creator" => RankingType.Creator, "donor" => RankingType.Donor, _ => RankingType.Comprehensive }; var rankingPeriod = period?.ToLowerInvariant() switch { "today" => RankingPeriod.Today, "yesterday" => RankingPeriod.Yesterday, "week" => RankingPeriod.Week, "last-month" or "lastmonth" => RankingPeriod.LastMonth, "all" => RankingPeriod.All, _ => RankingPeriod.Month }; var query = new Application.Features.Api.Ranking.GetMyRank.Query(memberID.Value, rankingType, rankingPeriod, category); var data = await sender.Send(query, ct); return ApiResponse.Ok(data); }) .WithTags("Ranking") .RequireAuthorization(); } }