2023-02-14 19:14:19 +01:00
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
using Application.Common.Extensions;
|
|
|
|
|
using Application.Common.Helpers;
|
|
|
|
|
using Application.Common.Models;
|
2023-02-16 08:26:13 +01:00
|
|
|
|
using Application.Dto;
|
2023-02-14 19:14:19 +01:00
|
|
|
|
using Application.Interfaces;
|
2023-02-16 08:26:13 +01:00
|
|
|
|
using Application.Mappers;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-02-14 19:14:19 +01:00
|
|
|
|
|
|
|
|
|
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-14 19:14:19 +01:00
|
|
|
|
{
|
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();
|
|
|
|
|
|
2023-02-14 19:14:19 +01:00
|
|
|
|
var container = new MonthlyScoreRankContainer
|
|
|
|
|
{
|
2023-02-16 08:26:13 +01:00
|
|
|
|
Ranks = dtoList,
|
2023-02-14 19:14:19 +01:00
|
|
|
|
Status = new RankStatus
|
|
|
|
|
{
|
2023-02-16 08:26:13 +01:00
|
|
|
|
TableName = "MonthlyScoreRank",
|
2023-02-14 19:14:19 +01:00
|
|
|
|
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-14 19:14:19 +01:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-16 08:26:13 +01:00
|
|
|
|
return new ServiceResult<string>(container.SerializeCardData());
|
2023-02-14 19:14:19 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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();
|
2023-02-14 19:14:19 +01:00
|
|
|
|
|
|
|
|
|
[XmlElement("ranking_status")]
|
|
|
|
|
public RankStatus Status { get; set; } = new();
|
|
|
|
|
}
|
|
|
|
|
|