36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
|
using DamageAssesment.Api.SurveyResponses.Bases;
|
|||
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|||
|
using DamageAssesment.Api.SurveyResponses.Models;
|
|||
|
using Newtonsoft.Json;
|
|||
|
|
|||
|
namespace DamageAssesment.Api.SurveyResponses.Providers
|
|||
|
{
|
|||
|
public class LocationServiceProvider :ServiceProviderBase, ILocationServiceProvider
|
|||
|
{
|
|||
|
public LocationServiceProvider(IConfiguration configuration, HttpClient httpClient, ILogger<LocationServiceProvider> logger) : base(configuration, httpClient, logger, "/api/Locations", configuration.GetValue<string>("EndPointSettings:LocationUrlBase"))
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
public async Task<List<Location>> getLocationsAsync()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
httpClient.BaseAddress = new Uri(urlBase);
|
|||
|
var response = await httpClient.GetAsync(ressource);
|
|||
|
response.EnsureSuccessStatusCode();
|
|||
|
var responseString = await response.Content.ReadAsStringAsync();
|
|||
|
var locations = JsonConvert.DeserializeObject<List<Location>>(responseString);
|
|||
|
|
|||
|
if (locations == null || !locations.Any())
|
|||
|
return null;
|
|||
|
else return locations;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: LocationServiceProvider.getLocationsAsync()");
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|