1
0
mirror of synced 2024-12-18 17:25:54 +01:00
GC-local-server-rewrite/Application/Game/Rank/GetPlayNumRankQuery.cs
2023-02-16 16:53:02 +08:00

62 lines
1.8 KiB
C#

using System.Diagnostics;
using Application.Common.Helpers;
namespace Application.Game.Rank;
public record GetPlayNumRankQuery(): IRequestWrapper<string>;
public class GetPlayNumRankQueryHandler : IRequestHandlerWrapper<GetPlayNumRankQuery, string>
{
private readonly ICardDbContext cardDbContext;
public GetPlayNumRankQueryHandler(ICardDbContext cardDbContext)
{
this.cardDbContext = cardDbContext;
}
public async Task<ServiceResult<string>> Handle(GetPlayNumRankQuery request, CancellationToken cancellationToken)
{
var ranks = await cardDbContext.PlayNumRanks.OrderBy(rank => rank.Rank)
.Take(30).ToListAsync(cancellationToken: cancellationToken);
var status = new RankStatus
{
TableName = "PlayNumRank",
StartDate = TimeHelper.DateToString(Process.GetCurrentProcess().StartTime.Date),
EndDate = TimeHelper.DateToString(DateTime.Today),
Rows = ranks.Count,
Status = 1
};
var dtoList = ranks.Select((rank, i) =>
{
var dto = rank.PlayNumRankToDto();
dto.Id = i;
return dto;
}).ToList();
var container = new PlayNumRankContainer
{
Ranks = dtoList,
Status = status
};
var result = container.SerializeCardData();
return new ServiceResult<string>(result);
}
}
[XmlRoot("root")]
public class PlayNumRankContainer
{
[XmlArray(ElementName = "play_num_rank")]
[XmlArrayItem(ElementName = "record")]
// ReSharper disable once UnusedAutoPropertyAccessor.Global
public List<PlayNumRankDto> Ranks { get; init; } = new();
[XmlElement("ranking_status")]
public RankStatus Status { get; set; } = new();
}