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

32 lines
1.3 KiB
C#
Raw Normal View History

using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.Responses.Models;
2023-08-15 22:52:30 -05:00
using Newtonsoft.Json;
namespace DamageAssesment.Api.Responses.Services
2023-08-15 22:52:30 -05:00
{
public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider
{
public LocationServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<LocationServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Location"), configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
2023-08-15 22:52:30 -05:00
{
}
public async Task<List<Location>> getLocationsAsync(string token)
2023-08-15 22:52:30 -05:00
{
try
{
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
var locations = JsonConvert.DeserializeObject<List<Location>>(responseJsonString);
2023-08-15 22:52:30 -05:00
if (locations == null || !locations.Any())
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()");
return new List<Location>();
2023-08-15 22:52:30 -05:00
}
}
}
}