public async Task NotifyNewDeals(ApplicationConfiguration applicationConfiguration) { var htmlContent = await _htmlContentLoader.Load(); var deals = _htmlContentParser.Parse(htmlContent); // TODO refactor to detect good deals with different criteria var bestDeals = deals.Where(d => d.Votes > 100); foreach (var deal in bestDeals) { var isDealNew = await _dealDataAccess.IsDealNew(deal); if (isDealNew) { _logger.LogDebug($"Deal with title {deal.Title} at price {deal.Price} found. Attempting to notify"); var notificationSuccessful = await _dealNotifier.Notify(deal, applicationConfiguration); // dont save the deal to the DB in case email notification failed due to // having exceeded the free quota, if the deal is still alive next day, we can still notify if (notificationSuccessful) { await _dealDataAccess.SaveDeal(deal); _logger.LogInformation($"Successfully notified and saved deal {deal}"); } } else { _logger.LogDebug($"Deal was found but is not new, skipping notification. Deal: {deal}"); } } }
public async Task NotifyNewDeals() { var htmlContent = await _htmlContentLoader.Load(); var deals = _htmlContentParser.Parse(htmlContent); // TODO refactor to detect good deals with different criteria var bestDeals = deals.Where(d => d.Votes > 100); foreach (var deal in bestDeals) { var isDealNew = await _dealDataAccess.IsDealNew(deal); if (isDealNew) { _logger.LogDebug($"Deal with title {deal.Title} at price {deal.Price} found"); await _dealDataAccess.SaveDeal(deal); } } }