51 lines
2.0 KiB
C#
51 lines
2.0 KiB
C#
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
|
using DamageAssesment.Api.SurveyResponses.Models;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
|
{
|
|
public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
|
|
{
|
|
public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Survey"), configuration.GetValue<string>("EndPointSettings:SurveyUrlBase"))
|
|
{
|
|
}
|
|
|
|
public async Task<List<Survey>> getSurveysAsync()
|
|
{
|
|
try
|
|
{
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString);
|
|
|
|
if (surveys == null || !surveys.Any())
|
|
return new List<Survey>();
|
|
else return surveys;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveysAsync()");
|
|
return new List<Survey>();
|
|
}
|
|
}
|
|
|
|
public async Task<Survey> getSurveyAsync(int surveyId)
|
|
{
|
|
try
|
|
{
|
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyById"), surveyId);
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
|
|
|
|
if (survey == null )
|
|
return null;
|
|
else return survey;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveyAsync()");
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|