Update rank service to handle dealing with rank entries that dont make it on the list and adding start of unit tests

This commit is contained in:
2021-11-07 20:50:34 -05:00
parent e14f7fae74
commit 896b8c8dd1
7 changed files with 64 additions and 22 deletions

View File

@@ -31,6 +31,10 @@ namespace TOOHUCardAPI.Data.Services
{
int bonus = AppSettings.DefaultRankBonus;
int index = allEntries.FindIndex(i => i.Id == entry.Id)+1;
if (index <= 0)
{
index = allEntries.Count + 1;
}
switch (index)
{
case <= 4:
@@ -77,7 +81,27 @@ namespace TOOHUCardAPI.Data.Services
TowersUsed = towersUsed,
UpdateTime = DateTime.Now
};
toUpload = await _rankRepository.InsertRankEntry(toUpload);
var previousEntry = await _rankRepository.GetRankEntry(toUpload.User.SteamId, toUpload.RankType);
bool shouldPushNew = true;
if (previousEntry != null)
{
if (previousEntry.Wave < toUpload.Wave)
{
await ResetRank(toUpload.User.SteamId, toUpload.RankType);
}
else if (previousEntry.Wave == toUpload.Wave && previousEntry.Damage < toUpload.Damage)
{
await ResetRank(toUpload.User.SteamId, toUpload.RankType);
}
else
{
shouldPushNew = false;
}
}
if (shouldPushNew)
{
toUpload = await _rankRepository.InsertRankEntry(toUpload);
}
List<RankEntry> allEntries = (await _rankRepository.GetRankEntries(toUpload.RankType)).ToList();
await _userService.UpdateUserAccountDetails(entry.SteamId, entry.UserId, entry.Username);
await _userService.UpdateUserMaxWave(entry.SteamId, entry.Wave, toUpload.RankType);