DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Services/RegionServiceProvider.cs

31 lines
1.2 KiB
C#

using DamageAssesment.Api.SurveyResponses.Interfaces;
using DamageAssesment.Api.SurveyResponses.Models;
using Newtonsoft.Json;
namespace DamageAssesment.Api.SurveyResponses.Services
{
public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider
{
public RegionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<RegionServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Region"), configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
{
}
public async Task<List<Region>> getRegionsAsync()
{
try
{
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString);
if (regions == null || !regions.Any())
return new List<Region>();
else return regions;
}
catch (Exception ex)
{
logger?.LogError($"Exception Found : {ex.Message} - Ref: RegionServiceProvider.getRegionsAsync()");
return new List<Region>();
}
}
}
}