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 SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Survey"), configuration.GetValue<string>("EndPointSettings:SurveyUrlBase"))
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<Survey>> getSurveysAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (surveys == null || !surveys.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Survey>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return surveys;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveysAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Survey>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Survey> getSurveyAsync(int surveyId)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyById"), surveyId);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (survey == null )
|
|
|
|
|
return null;
|
|
|
|
|
else return survey;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveyAsync()");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|