2023-09-26 15:22:26 -05:00
|
|
|
|
using DamageAssesment.Api.Responses.Interfaces;
|
|
|
|
|
using DamageAssesment.Api.Responses.Models;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2023-09-26 15:22:26 -05:00
|
|
|
|
namespace DamageAssesment.Api.Responses.Services
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
public class RegionServiceProvider : ServiceProviderBase, IRegionServiceProvider
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
}
|
2023-09-19 23:32:30 -05:00
|
|
|
|
public async Task<List<Region>> getRegionsAsync(string token)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-19 23:32:30 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var regions = JsonConvert.DeserializeObject<List<Region>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (regions == null || !regions.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
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()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Region>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|