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

33 lines
1.3 KiB
C#

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, IHttpUtil httpUtil, ILogger<RegionServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Regions", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
{
}
public async Task<List<Region>> getRegionsAsync()
{
try
{
var url = urlBase + ressource;
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>();
}
}
}
}