diff --git a/Dodo1000Bot.Messengers.Telegram/TelegramNotifyService.cs b/Dodo1000Bot.Messengers.Telegram/TelegramNotifyService.cs index 9a53e6f..459486e 100644 --- a/Dodo1000Bot.Messengers.Telegram/TelegramNotifyService.cs +++ b/Dodo1000Bot.Messengers.Telegram/TelegramNotifyService.cs @@ -16,13 +16,13 @@ namespace Dodo1000Bot.Messengers.Telegram; public class TelegramNotifyService : INotifyService { private readonly ILogger _log; - private readonly IUsersRepository _usersRepository; + private readonly IUsersService _usersService; private readonly ITelegramBotClient _client; - public TelegramNotifyService(IUsersRepository usersRepository, ITelegramBotClient client, + public TelegramNotifyService(IUsersService usersService, ITelegramBotClient client, ILogger log) { - _usersRepository = usersRepository; + _usersService = usersService; _client = client; _log = log; } @@ -37,7 +37,7 @@ public async Task> NotifyAbout(IList users = await _usersRepository.GetUsers(Source.Telegram, cancellationToken); + IList users = await _usersService.GetUsers(Source.Telegram, cancellationToken); if (users?.Any() != true) { @@ -81,7 +81,7 @@ await _client.SendTextMessageAsync(messengerUserId, notification.Payload.Text, catch (ApiRequestException e) when (e.ErrorCode == 403) { _log.LogWarning(e, "Error while send notification to {MessengerUserId}, so user will be deleted", messengerUserId); - await _usersRepository.Delete(user, cancellationToken); + await _usersService.Delete(user, cancellationToken); return pushedNotifications; } catch (Exception e) @@ -104,7 +104,7 @@ await _client.SendTextMessageAsync(messengerUserId, notification.Payload.Text, public async Task SendToAdmin(Notification notification, CancellationToken cancellationToken) { - var admins = await _usersRepository.GetAdmins(Source.Telegram, cancellationToken); + var admins = await _usersService.GetAdmins(Source.Telegram, cancellationToken); foreach (var admin in admins) { diff --git a/Dodo1000Bot.Services/Interfaces/IUsersService.cs b/Dodo1000Bot.Services/Interfaces/IUsersService.cs index 10f743e..308cace 100644 --- a/Dodo1000Bot.Services/Interfaces/IUsersService.cs +++ b/Dodo1000Bot.Services/Interfaces/IUsersService.cs @@ -14,5 +14,5 @@ public interface IUsersService Task> GetUsers(Source messengerType, CancellationToken cancellationToken); - Task Count(CancellationToken cancellationToken); + Task> GetAdmins(Source telegram, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/Dodo1000Bot.Services/UsersService.cs b/Dodo1000Bot.Services/UsersService.cs index 59a509b..0199d58 100644 --- a/Dodo1000Bot.Services/UsersService.cs +++ b/Dodo1000Bot.Services/UsersService.cs @@ -71,6 +71,9 @@ public async Task Delete(User user, CancellationToken cancellationToken) public Task> GetUsers(Source messengerType, CancellationToken cancellationToken) => _usersRepository.GetUsers(messengerType, cancellationToken); + public Task> GetAdmins(Source messengerType, CancellationToken cancellationToken) => + _usersRepository.GetAdmins(messengerType, cancellationToken); + public async Task Count(CancellationToken cancellationToken) { var count = await _usersRepository.Count(cancellationToken);