public ValidationResult ValidateStreetsQueryParams(StreetsQueryParams filtersToValidate) { List <ApiErrorMessage> myErrors = new List <ApiErrorMessage>(); bool hasError = false; //StreetName if (!string.IsNullOrWhiteSpace(filtersToValidate.StreetName)) { var error = ValidateStreetName(filtersToValidate.StreetName); if (error != null) { myErrors.Add(error); hasError = true; } } //Gazetteer if (!string.IsNullOrWhiteSpace(filtersToValidate.Gazetteer)) { //?#? To Implement } ValidationResult validationObject = new ValidationResult(); validationObject.ErrorOccurred = hasError; validationObject.ErrorMessages = myErrors; return(validationObject); }
private List <FilterObject> formatAndAddToFilter(StreetsQueryParams queryParams) { queryParams = _formatter.FormatStreetsQueryParams(queryParams); List <FilterObject> filterObjects = _fob.ProcessQueryParamsToFilterObjects(queryParams, _queryBuilder.GetColumnMappings()); return(filterObjects); }
public async Task<JsonResult> GetStreets([FromQuery]string StreetName = null, [FromQuery]int? Limit = GlobalConstants.LIMIT, [FromQuery]int? Offset = GlobalConstants.OFFSET) { try { StreetsQueryParams queryParams = new StreetsQueryParams(); queryParams.StreetName = WebUtility.UrlDecode(StreetName); //queryParams.Gazetteer = WebUtility.UrlDecode(Gazetteer.ToString()); ValidationResult validatorFilterErrors = _validator.ValidateStreetsQueryParams(queryParams); if (!validatorFilterErrors.ErrorOccurred) { Pagination pagination = new Pagination(); pagination.limit = Limit ?? default(int); pagination.offset = Offset ?? default(int); var result = await _streetsActions.GetStreets( queryParams, pagination); var json = Json(new { result, ErrorCode = "0", ErrorMessage = "" }); json.StatusCode = 200; json.ContentType = "application/json"; return json; } else { var errors = validatorFilterErrors.ErrorMessages; var json = Json(errors); json.StatusCode = 400; json.ContentType = "application/json"; return json; } } catch (Exception ex) { var errors = new List<ApiErrorMessage> { new ApiErrorMessage { developerMessage = ex.Message, userMessage = "We had some problems processing your request" } }; _logger.LogError(ex.Message); var json = Json(errors); json.StatusCode = 500; json.ContentType = "application/json"; return json; } }
public async Task <object> GetStreets(StreetsQueryParams queryParams, Pagination pagination) { List <FilterObject> filterObjects = formatAndAddToFilter(queryParams); string connString = llpgConnString; pagination = await callDatabaseAsyncPagination(filterObjects, pagination, connString); DataTable dataTable = await callDatabaseAsync(filterObjects, pagination, connString); var resultset = new { resultset = pagination }; var result = _detailsMapper.MapStreetDetails(dataTable); return(new { Addresses = result, metadata = resultset }); }
public StreetsQueryParams FormatStreetsQueryParams(StreetsQueryParams queryParams) { queryParams.StreetName = String.IsNullOrWhiteSpace(queryParams.StreetName) ? null : FormatStreetName(queryParams.StreetName); return(queryParams); }