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

31 lines
1.2 KiB
C#
Raw Permalink Normal View History

2023-10-04 17:45:51 -05:00
using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.Responses.Models;
2023-08-15 22:52:30 -05:00
using Newtonsoft.Json;
2023-10-04 17:45:51 -05:00
namespace DamageAssesment.Api.Responses.Services
2023-08-15 22:52:30 -05:00
{
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"))
2023-08-15 22:52:30 -05:00
{
}
public async Task<List<Region>> getRegionsAsync()
{
try
{
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString);
2023-08-15 22:52:30 -05:00
if (regions == null || !regions.Any())
return new List<Region>();
2023-08-15 22:52:30 -05:00
else return regions;
}
catch (Exception ex)
{
logger?.LogError($"Exception Found : {ex.Message} - Ref: RegionServiceProvider.getRegionsAsync()");
return new List<Region>();
2023-08-15 22:52:30 -05:00
}
}
}
}