public async Task <WebHookFeedSearchResult> SearchAsync(WebhookFeedSearchCriteria searchCriteria) { using (var repository = _webHookRepositoryFactory()) { repository.DisableChangesTracking(); var result = AbstractTypeFactory <WebHookFeedSearchResult> .TryCreateInstance(); var sortInfos = BuildSortExpression(searchCriteria); var query = BuildQuery(repository, searchCriteria); result.TotalCount = await query.CountAsync(); if (searchCriteria.Take > 0) { var ids = await query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id) .Select(x => x.Id) .Skip(searchCriteria.Skip).Take(searchCriteria.Take) .ToArrayAsync(); result.Results = (await GetByIdsAsync(ids)).OrderBy(x => Array.IndexOf(ids, x.Id)).ToList(); } return(result); } }
protected virtual IList <SortInfo> BuildSortExpression(WebhookFeedSearchCriteria criteria) { var sortInfos = criteria.SortInfos; if (sortInfos.IsNullOrEmpty()) { sortInfos = new[] { new SortInfo { SortColumn = nameof(WebHookFeedEntryEntity.CreatedDate), SortDirection = SortDirection.Descending } }; } return(sortInfos); }
/// <summary> /// Logs Success webHook notifications by incrementing AttemptCount. /// </summary> /// <param name="feedEntry">Entry with the event data.</param> /// <returns>Saved feed entry.</returns> protected async Task <WebhookFeedEntry> LogSuccessAsync(WebhookFeedEntry feedEntry) { var criteria = new WebhookFeedSearchCriteria() { RecordTypes = new[] { (int)WebhookFeedEntryType.Success }, WebHookIds = new[] { feedEntry.WebHookId }, Skip = 0, Take = 1, }; var feedEntrySearchResult = await _webHookFeedSearchService.SearchAsync(criteria); var feedEntryToSave = feedEntrySearchResult.Results.FirstOrDefault(); if (feedEntryToSave == null) { feedEntryToSave = feedEntry; } feedEntryToSave.AttemptCount++; await _webHookFeedService.SaveChangesAsync(new[] { feedEntryToSave }); return(feedEntryToSave); }
public async Task <ActionResult <WebHookFeedSearchResult> > SearchWebhookFeed([FromBody] WebhookFeedSearchCriteria criteria) { var result = await _webHookFeedSearchService.SearchAsync(criteria); return(Ok(result)); }
protected virtual IQueryable <WebHookFeedEntryEntity> BuildQuery(IWebHookRepository repository, WebhookFeedSearchCriteria searchCriteria) { var query = repository.WebHookFeedEntries; if (!string.IsNullOrWhiteSpace(searchCriteria.SearchPhrase)) { query = query.Where(x => x.EventId.Contains(searchCriteria.SearchPhrase)); } if (!searchCriteria.WebHookIds.IsNullOrEmpty()) { query = query.Where(x => searchCriteria.WebHookIds.Contains(x.WebHookId)); } if (!searchCriteria.EventIds.IsNullOrEmpty()) { query = query.Where(x => searchCriteria.EventIds.Contains(x.EventId)); } if (!searchCriteria.RecordTypes.IsNullOrEmpty()) { query = query.Where(x => searchCriteria.RecordTypes.Contains(x.RecordType)); } if (!searchCriteria.Statuses.IsNullOrEmpty()) { query = query.Where(x => searchCriteria.Statuses.Contains(x.Status)); } return(query); }