Skip to content

Commit

Permalink
fixing general ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavobigardi committed Jun 9, 2021
1 parent 7dc0864 commit ee2f069
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/DexQuiz.Core/Services/RankingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public async Task<IEnumerable<GeneralRanking>> GetGeneralRankingForUserAsync(int
int counter = 1;
string username = (await _userRepository.FindAsync(userId))?.Name;

return (await _trackRankingRepository.FindAsync(r => r.CompletedTime != null))
var result = (await _trackRankingRepository.FindAsync(r => r.CompletedTime != null))
.GroupBy(
g => new { UserId = g.UserId, Username = userId == g.UserId ? username : "Participante" },
p => new { p.Points, p.CompletedTime },
Expand All @@ -250,6 +250,17 @@ public async Task<IEnumerable<GeneralRanking>> GetGeneralRankingForUserAsync(int
r.Position = counter++;
return r;
}).ToList();

var ranking = result.Take(top).ToList();

if (!ranking.Any(r => r.UserId == userId))
{
var rankingUser = result.FirstOrDefault(u => u.UserId == userId);
if (rankingUser != null)
ranking.Add(rankingUser);
}

return ranking.OrderBy(x => x.Position).ThenBy(x => x.CompletedTime);
}
}
}

0 comments on commit ee2f069

Please sign in to comment.