1
0
mirror of synced 2024-12-18 09:15:54 +01:00
GC-local-server-rewrite/Application/Game/Rank/GetMonthlyScoreRankQuery.cs

58 lines
1.8 KiB
C#
Raw Normal View History

2023-02-16 09:53:02 +01:00
using Application.Common.Helpers;
namespace Application.Game.Rank;
public record GetMonthlyScoreRankQuery() : IRequestWrapper<string>;
public class GetMonthlyScoreRankQueryHandler : IRequestHandlerWrapper<GetMonthlyScoreRankQuery, string>
{
2023-02-16 08:26:13 +01:00
private readonly ICardDbContext cardDbContext;
public GetMonthlyScoreRankQueryHandler(ICardDbContext cardDbContext)
{
this.cardDbContext = cardDbContext;
}
public async Task<ServiceResult<string>> Handle(GetMonthlyScoreRankQuery request, CancellationToken cancellationToken)
{
2023-02-16 08:26:13 +01:00
var ranks = await cardDbContext.MonthlyScoreRanks.OrderBy(rank => rank.Rank)
.Take(30).ToListAsync(cancellationToken: cancellationToken);
var dtoList = ranks.Select((rank, i) =>
{
var dto = rank.ScoreRankToDto();
dto.Id = i;
dto.Rank2 = dto.Rank;
return dto;
}).ToList();
var container = new MonthlyScoreRankContainer
{
2023-02-16 08:26:13 +01:00
Ranks = dtoList,
Status = new RankStatus
{
2023-02-16 08:26:13 +01:00
TableName = "MonthlyScoreRank",
StartDate = TimeHelper.DateToString(DateTime.Today),
EndDate = TimeHelper.DateToString(DateTime.Today),
2023-02-16 08:26:13 +01:00
Rows = dtoList.Count,
Status = 1
}
};
2023-02-16 08:26:13 +01:00
return new ServiceResult<string>(container.SerializeCardData());
}
}
[XmlRoot("root")]
public class MonthlyScoreRankContainer
{
[XmlArray(ElementName = "m_score_rank")]
[XmlArrayItem(ElementName = "record")]
// ReSharper disable once UnusedAutoPropertyAccessor.Global
2023-02-16 08:26:13 +01:00
public List<ScoreRankDto> Ranks { get; init; } = new();
[XmlElement("ranking_status")]
public RankStatus Status { get; set; } = new();
}