public async Task <IEnumerable <PropertyModel> > GetByQueryAsync(PropertySearchModel searchModel)
        {
            Uri url      = new Uri($"properties?{searchModel.GetQueryParameter()}", UriKind.Relative);
            var response = await _apiGateway.ExecuteRequest <List <PropertyApiResponse> >(HttpClientNames.Properties, url);

            if (!response.IsSuccess)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.PropertiesFailure);
            }

            return(response.Content.ToDomain());
        }
Example #2
0
        public async Task <PropertyAlertList> GetLocationAlertsAsync(string propertyReference)
        {
            _logger.LogInformation($"Starting to gather alerts for {propertyReference}");

            var url      = new Uri($"cautionary-alerts/sheets/properties/{propertyReference}", UriKind.Relative);
            var response = await _apiGateway.ExecuteRequest <PropertyAlertsApiResponse>(HttpClientNames.Alerts, url);

            if (response.Status == HttpStatusCode.NotFound)
            {
                _logger.LogInformation($"Call didn't find any alerts for {propertyReference}");
                return(EmptyPropertyAlertList(propertyReference));
            }

            if (!response.IsSuccess)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.LocationAlertsFailure);
            }

            _logger.LogInformation($"Finished gathering alerts for {propertyReference} - there were {response.Content?.Alerts.Count ?? 0} alerts");


            return(response.Content.ToDomain());
        }
        public async Task <SearchForPropertiesResponse> Search(SearchForPropertiesModel searchModel)
        {
            _logger.LogInformation($"Calling HousingSearchAPI");

            Uri url = new Uri($"search/assets?{searchModel.GetQueryParameters()}", UriKind.Relative);

            var response = await _apiGateway.ExecuteRequest <HousingSearchAPIResponse>(HttpClientNames.HousingSearch, url);

            if (!response.IsSuccess)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.PropertiesFailure);
            }

            _logger.LogInformation($"Call to HousingSearchAPI was successful with [{response?.Content?.Results?.Assets?.Count}] properties returned and [{response?.Content?.Total}] total results");

            return(response.Content.ToResponse());
        }
Example #4
0
        public async Task <AssetResponseObject> GetById(string assetId)
        {
            Uri url      = new Uri($"assets/assetId/{assetId}", UriKind.Relative);
            var response = await _apiGateway.ExecuteRequest <AssetResponseObject>(HttpClientNames.Asset, url);

            if (response.Status == HttpStatusCode.NotFound)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                return(null);
            }

            if (!response.IsSuccess)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.PropertyFailure);
            }

            return(response.Content);
        }
        private async Task <ResidentContactDetails> GetContactDetailsAsync(HouseholdMember householdMember)
        {
            Uri url      = new Uri($"contactDetails?targetId={householdMember.Id}", UriKind.Relative);
            var response = await _apiGateway.ExecuteRequest <ContactDetailsResponse>(HttpClientNames.ContactDetails, url);

            if (response.Status == HttpStatusCode.NotFound)
            {
                _logger.LogInformation($"ContactDetails not found for targetId: {householdMember.Id}");

                return(null);
            }

            if (!response.IsSuccess)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.ContactsFailure);
            }

            return(response.Content.ToDomain(householdMember));
        }
        public async Task <IEnumerable <ResidentContact> > GetByHouseholdReferenceAsync(string householdReference)
        {
            if (string.IsNullOrEmpty(householdReference))
            {
                return(Enumerable.Empty <ResidentContact>());
            }

            Uri url      = new Uri($"households?house_reference={householdReference}&active_tenancies_only=true", UriKind.Relative);
            var response = await _apiGateway.ExecuteRequest <HousingResidentInformationApiResponse>(HttpClientNames.Contacts, url);

            if (response.Status == HttpStatusCode.NotFound)
            {
                throw new ResourceNotFoundException(Resources.Contacts_Not_Found);
            }

            if (!response.IsSuccess)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.ContactsFailure);
            }

            return(response.Content.ToDomain());
        }
        public async Task <TenureInformation?> GetById(string?tenancyId)
        {
            //  Asset doesnt have tenure
            if (tenancyId == null)
            {
                return(null);
            }

            Uri url      = new Uri($"tenures/{tenancyId}", UriKind.Relative);
            var response = await _apiGateway.ExecuteRequest <TenureResponseObject>(HttpClientNames.TenureInformation, url);

            if (!response.IsSuccess && response.Status != HttpStatusCode.NotFound)
            {
                _logger.LogError($"Call to {url} failed with {response.Status}");
                throw new ApiException(response.Status, Resources.TenancyFailure);
            }

            if (response.Status == HttpStatusCode.NotFound)
            {
                return(null);
            }

            return(response.Content?.ToDomain());
        }