This commit is contained in:
kislovdm
2026-03-10 14:23:42 +03:00
commit 6c8b9334c8
106 changed files with 4538 additions and 0 deletions
@@ -0,0 +1,11 @@
using PepperBot.Domain;
namespace PepperBot.Application.Interfaces;
public interface IDealRepository
{
Task InitializeAsync(CancellationToken cancellationToken);
Task<bool> ExistsAsync(long id, CancellationToken cancellationToken);
Task AddAsync(Deal deal, CancellationToken cancellationToken);
}
@@ -0,0 +1,9 @@
using PepperBot.Domain;
namespace PepperBot.Application.Interfaces;
public interface IPepperClient
{
Task<IReadOnlyList<Deal>> GetLatestDealsAsync(CancellationToken cancellationToken);
}
@@ -0,0 +1,9 @@
using PepperBot.Domain;
namespace PepperBot.Application.Interfaces;
public interface ITelegramNotifier
{
Task NotifyNewDealAsync(Deal deal, CancellationToken cancellationToken);
}
@@ -0,0 +1,44 @@
using Microsoft.Extensions.Logging;
using PepperBot.Application.Interfaces;
using PepperBot.Domain;
namespace PepperBot.Application.Services;
public class DealService
{
private readonly IPepperClient _pepperClient;
private readonly IDealRepository _repository;
private readonly ITelegramNotifier _notifier;
private readonly ILogger<DealService> _logger;
public DealService(
IPepperClient pepperClient,
IDealRepository repository,
ITelegramNotifier notifier,
ILogger<DealService> logger)
{
_pepperClient = pepperClient;
_repository = repository;
_notifier = notifier;
_logger = logger;
}
public async Task CheckAndNotifyAsync(CancellationToken cancellationToken)
{
var deals = await _pepperClient.GetLatestDealsAsync(cancellationToken);
foreach (var deal in deals)
{
if (await _repository.ExistsAsync(deal.Id, cancellationToken))
{
continue;
}
_logger.LogInformation("Новая скидка: {Title} ({Id})", deal.Title, deal.Id);
await _repository.AddAsync(deal, cancellationToken);
await _notifier.NotifyNewDealAsync(deal, cancellationToken);
}
}
}