Merge branch 'Refactor' of https://github.com/asesidaa/TaikoLocalServer into LoginRefactor
This commit is contained in:
commit
75e90d9aa2
@ -22,27 +22,37 @@ public class GetSelfBestQueryHandler(IGameDataService gameDataService, TaikoDbCo
|
||||
requestSet.ExceptWith(invalidSongIds);
|
||||
}
|
||||
|
||||
var selfbestScores = await context.SongBestData
|
||||
var selfBestScores = await context.SongBestData
|
||||
.Where(datum => datum.Baid == request.Baid &&
|
||||
requestSet.Contains(datum.SongId) &&
|
||||
(datum.Difficulty == requestDifficulty ||
|
||||
(datum.Difficulty == Difficulty.UraOni && requestDifficulty == Difficulty.Oni)))
|
||||
.OrderBy(datum => datum.SongId)
|
||||
.ToListAsync(cancellationToken);
|
||||
var selfBestList = selfbestScores.ConvertAll(datum => new CommonSelfBestResponse.SelfBestData
|
||||
var selfBestList = new List<CommonSelfBestResponse.SelfBestData>();
|
||||
foreach (var songId in request.SongIdList)
|
||||
{
|
||||
SongNo = datum.SongId,
|
||||
SelfBestScore = datum.BestScore,
|
||||
UraBestScore = datum.Difficulty == Difficulty.UraOni ? datum.BestScore : 0,
|
||||
SelfBestScoreRate = datum.BestRate,
|
||||
UraBestScoreRate = datum.Difficulty == Difficulty.UraOni ? datum.BestRate : 0
|
||||
});
|
||||
// For songs that don't have a score, add them to the response with 0s
|
||||
var missingSongs = requestSet.Except(selfBestList.Select(datum => datum.SongNo));
|
||||
selfBestList.AddRange(missingSongs.Select(songNo => new CommonSelfBestResponse.SelfBestData
|
||||
{
|
||||
SongNo = songNo
|
||||
}));
|
||||
var selfBest = new CommonSelfBestResponse.SelfBestData();
|
||||
var selfBestScore = selfBestScores
|
||||
.FirstOrDefault(datum => datum.SongId == songId &&
|
||||
datum.Difficulty == requestDifficulty);
|
||||
var uraSelfBestScore = selfBestScores
|
||||
.FirstOrDefault(datum => datum.SongId == songId &&
|
||||
datum.Difficulty == Difficulty.UraOni && requestDifficulty == Difficulty.Oni);
|
||||
|
||||
selfBest.SongNo = songId;
|
||||
if (selfBestScore is not null)
|
||||
{
|
||||
selfBest.SelfBestScore = selfBestScore.BestScore;
|
||||
selfBest.SelfBestScoreRate = selfBestScore.BestRate;
|
||||
}
|
||||
if (uraSelfBestScore is not null)
|
||||
{
|
||||
selfBest.UraBestScore = uraSelfBestScore.BestScore;
|
||||
selfBest.UraBestScoreRate = uraSelfBestScore.BestRate;
|
||||
}
|
||||
|
||||
selfBestList.Add(selfBest);
|
||||
}
|
||||
|
||||
var response = new CommonSelfBestResponse
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user