コード例 #1
0
        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);
        }
コード例 #2
0
        private List <FilterObject> formatAndAddToFilter(StreetsQueryParams queryParams)
        {
            queryParams = _formatter.FormatStreetsQueryParams(queryParams);

            List <FilterObject> filterObjects = _fob.ProcessQueryParamsToFilterObjects(queryParams, _queryBuilder.GetColumnMappings());

            return(filterObjects);
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        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 });
        }
コード例 #5
0
 public StreetsQueryParams FormatStreetsQueryParams(StreetsQueryParams queryParams)
 {
     queryParams.StreetName = String.IsNullOrWhiteSpace(queryParams.StreetName) ? null : FormatStreetName(queryParams.StreetName);
     return(queryParams);
 }