public async Task <IEnumerable <SearchQueryLogEntry> > GetLogsAsync(SearchQueryLogsFilter filter)
        {
            var dbModels =
                await Context
                .SearchQueryLogEntries
                .Where(ComposeFilter(filter))
                .ToListAsync()
                .ConfigureAwait(false);

            return(Mapper.Map <IEnumerable <SearchQueryLogEntry> >(dbModels));
        }
        private Expression <Func <SearchQueryLogEntryDbModel, bool> > ComposeFilter(SearchQueryLogsFilter filter)
        {
            var exp = base.ComposeBaseFilter <SearchQueryLogEntryDbModel>(filter);

            if (!string.IsNullOrWhiteSpace(filter.UserId))
            {
                exp = PredicateExtensions.And(exp, entry => entry.UserId.ToLower().Contains(filter.UserId.ToLower()));
            }

            if (!string.IsNullOrWhiteSpace(filter.SearchCriterium))
            {
                exp = PredicateExtensions.And(exp, entry => entry.SearchCriterium.ToLower().Contains(filter.SearchCriterium.ToLower()));
            }

            if (!string.IsNullOrWhiteSpace(filter.FilterInfo))
            {
                exp = PredicateExtensions.And(exp, entry => entry.FilterInfo.ToLower().Contains(filter.FilterInfo.ToLower()));
            }

            return(exp);
        }
        public async Task ShouldGetFilteredEntries(string userId, string userName, string filterInfo, DateTime?dateFrom = null, DateTime?dateTo = null)
        {
            // Arrange
            Context.SearchQueryLogEntries.AddRange(SearchQueryLogEntryFaker.Generate(10));

            Context.SearchQueryLogEntries.Add(new SearchQueryLogEntryDbModel
            {
                UserId          = "alexpvt",
                SearchCriterium = "opera aida",
                FilterInfo      = "theaters, opera",
                EventDate       = DateTimeNow
            });

            await Context.SaveChangesAsync();

            var filter = new SearchQueryLogsFilter()
            {
                UserId          = userId,
                SearchCriterium = userName,
                FilterInfo      = filterInfo,
                DateFrom        = dateFrom,
                DateTo          = dateTo
            };

            // Act
            var entries = await _searchLogService.GetLogsAsync(filter);

            // Assert
            entries.Count().ShouldBeEqualTo(1);

            var entry = entries.Single();

            entry.UserId.ShouldBeEqualTo("alexpvt");
            entry.SearchCriterium.ShouldBeEqualTo("opera aida");
            entry.FilterInfo.ShouldBeEqualTo("theaters, opera");
            entry.EventDate.ShouldBeEqualTo(DateTimeNow);
        }
        public async Task <IActionResult> GetSearchQueryLogs([FromQuery] SearchQueryLogsFilter filter)
        {
            var result = await _loggingService.GetLogsAsync(filter);

            return(Ok(result));
        }