public ActionResult <IEnumerable <DTO.Brewery> > Index( [FromQuery] string by_city = null, [FromQuery] string by_name = null, [FromQuery] string by_state = null, [FromQuery] string by_tag = null, [FromQuery] string by_tags = null, [FromQuery] string by_type = null, [FromQuery] string sort = null, [FromQuery] int page = 1, [FromQuery] int per_page = 20 ) { // Validation if (!_validationConductor.CanSearch(by_state, by_type, out var errors)) { return(BadRequest()); } // Filtering var filter = _filterConductor.BuildFilter(by_name, by_state, by_city, by_type, BuildTags(by_tag, by_tags)); // Sorting var orderBy = _orderConductor.OrderByFields( sort? .Trim() .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(s => { if (s.FirstOrDefault() == '-') { return(new KeyValuePair <string, SortDirection>(s.Substring(1), SortDirection.DESC)); } return(new KeyValuePair <string, SortDirection>(s, SortDirection.ASC)); }) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value) ); // Return Results var dataResults = _breweryConductor.FindAll( filter: filter, orderBy: orderBy, skip: (page - 1) * per_page, take: per_page ); if (dataResults.HasErrors || dataResults.ResultObject is null) { return(BadRequest()); } return(_mapper.Map <IEnumerable <Brewery>, List <DTO.Brewery> >(dataResults.ResultObject)); }
public ActionResult <IEnumerable <DTO.AutocompleteBrewery> > Index( [FromQuery] string query = null, [FromQuery] string sort = null, [FromQuery] int page = 1, [FromQuery] int per_page = 20 ) { // Filtering var filter = _filterConductor.BuildSearchQueryFilter(query); // Return Results var dataResults = _breweryConductor.FindAll( filter: filter, skip: (page - 1) * per_page, take: per_page ); if (dataResults.HasErrors || dataResults.ResultObject is null) { return(BadRequest()); } return(_mapper.Map <IEnumerable <Brewery>, List <DTO.AutocompleteBrewery> >(dataResults.ResultObject)); }