using DamageAssesment.Api.SurveyResponses.Bases; using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.SurveyResponses.Models; using Newtonsoft.Json; namespace DamageAssesment.Api.SurveyResponses.Providers { public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider { public RegionServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger logger) : base(configuration, httpClient, logger, "/api/Regions", configuration.GetValue("EndPointSettings:LocationUrlBase")) { } public async Task> getRegionsAsync() { try { httpClient.BaseAddress = new Uri(urlBase); var response = await httpClient.GetAsync(ressource); response.EnsureSuccessStatusCode(); var responseString = await response.Content.ReadAsStringAsync(); var regions = JsonConvert.DeserializeObject>(responseString); if (regions == null || !regions.Any()) return null; else return regions; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: RegionServiceProvider.getRegionsAsync()"); return null; } } } }