Skip to content

Commit

Permalink
used IUsersService at TelegramNotifyService
Browse files Browse the repository at this point in the history
  • Loading branch information
granstel committed Mar 18, 2024
1 parent ef4e3bc commit 1543cdf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Dodo1000Bot.Messengers.Telegram/TelegramNotifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ namespace Dodo1000Bot.Messengers.Telegram;
public class TelegramNotifyService : INotifyService
{
private readonly ILogger<TelegramNotifyService> _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<TelegramNotifyService> log)
{
_usersRepository = usersRepository;
_usersService = usersService;
_client = client;
_log = log;
}
Expand All @@ -37,7 +37,7 @@ public async Task<IEnumerable<PushedNotification>> NotifyAbout(IList<Notificatio
return pushedNotifications;
}

IList<User> users = await _usersRepository.GetUsers(Source.Telegram, cancellationToken);
IList<User> users = await _usersService.GetUsers(Source.Telegram, cancellationToken);

if (users?.Any() != true)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion Dodo1000Bot.Services/Interfaces/IUsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface IUsersService

Task<IList<User>> GetUsers(Source messengerType, CancellationToken cancellationToken);

Task Count(CancellationToken cancellationToken);
Task<IList<User>> GetAdmins(Source telegram, CancellationToken cancellationToken);
}
3 changes: 3 additions & 0 deletions Dodo1000Bot.Services/UsersService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ public async Task Delete(User user, CancellationToken cancellationToken)
public Task<IList<User>> GetUsers(Source messengerType, CancellationToken cancellationToken) =>
_usersRepository.GetUsers(messengerType, cancellationToken);

public Task<IList<User>> GetAdmins(Source messengerType, CancellationToken cancellationToken) =>
_usersRepository.GetAdmins(messengerType, cancellationToken);

public async Task Count(CancellationToken cancellationToken)
{
var count = await _usersRepository.Count(cancellationToken);
Expand Down

0 comments on commit 1543cdf

Please sign in to comment.