public async Task <IEnumerable <Listing> > GetListingsAsync(GetListingsRequest request) { string key = request.Suburb?.ToLower() ?? "all"; var resultsBySuburb = await _cache.GetOrCreateAsync(key, entry => { entry.SlidingExpiration = TimeSpan.FromSeconds(ExpirationTimeInSeconds); entry.AbsoluteExpiration = DateTimeOffset.UtcNow.AddSeconds(ExpirationTimeInSeconds); _logger.LogInformation($"Retrieving results from database key : {key}"); return(_dbContext.Listings.Where(x => request.Suburb == null || x.Suburb.ToLower() == request.Suburb.ToLower()).ToListAsync()); }); var results = resultsBySuburb.Where(x => (request.CategoryType == null || x.CategoryType == request.CategoryType) && (request.StatusType == null || x.StatusType == request.StatusType)); if (request.Skip > 0) { results = results.Skip(request.Skip); } if (request.Take > 0) { results = results.Take(request.Take); } _logger.LogInformation($"{results.Count()} retrieved"); return(results); }
public async Task <IActionResult> GetListingsAsync([FromQuery] GetListingsRequest request) { _logger.LogInformation($"Getting Listing for payload : {request.ToJson()}"); var response = await _getListingsService.ExecuteAsync(request); return(Ok(response)); }
public async Task <GetListingsResponse> ExecuteAsync(GetListingsRequest request) { var listings = await _listingRepository.GetListingsAsync(request); _logger.LogInformation("Mapping entities to response"); var items = _mapper.Map <IEnumerable <Item> >(listings); _logger.LogInformation("Get listings successful"); return(new GetListingsResponse { Items = items, Total = items.Count() }); }