DamageAssessment_Backend/DamageAssesmentApi/DamageAssesment.Api.SurveyResponses/Services/LocationServiceProvider.cs
2023-09-04 21:59:21 -04:00

33 lines
1.3 KiB
C#

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