[reputation] Add rating.

This commit is contained in:
West14
2022-02-14 14:39:55 +02:00
parent f80b5d0da8
commit e885613c58
6 changed files with 95 additions and 11 deletions
@@ -1,4 +1,5 @@
using Kruzya.TelegramBot.Core.Extensions;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Kruzya.TelegramBot.Core.Service;
using Microsoft.EntityFrameworkCore;
using Telegram.Bot.Types;
@@ -54,6 +55,16 @@ public class ReputationService : IReputation
return Math.Round(senderValue == 0 ? 1 : Math.Sqrt(senderValue), 2);
}
public async Task<IEnumerable<IReputationEntity>> GetChatRatingAsync(Chat chat, int limit = 10, int offset = 0)
{
return await _reputationContext.UserReputation
.Where(r => r.ChatId == chat.Id && r.Value != 0D)
.OrderByDescending(r => r.Value)
.Skip(offset)
.Take(limit)
.ToListAsync();
}
private async Task<UserReputation?> FindUserReputation(Chat chat, User user)
{
return await _reputationContext.UserReputation.SingleOrDefaultAsync(