2023-09-04 20:59:21 -05:00
|
|
|
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using DamageAssesment.Api.SurveyResponses.Models;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2023-09-04 20:59:21 -05:00
|
|
|
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
public LocationServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<LocationServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Locations", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<Location>> getLocationsAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var url = urlBase + ressource;
|
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var locations = JsonConvert.DeserializeObject<List<Location>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (locations == null || !locations.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Location>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return locations;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: LocationServiceProvider.getLocationsAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Location>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|