2023-10-04 17:45:51 -05:00
|
|
|
|
using DamageAssesment.Api.Responses.Interfaces;
|
|
|
|
|
using DamageAssesment.Api.Responses.Models;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2023-10-04 17:45:51 -05:00
|
|
|
|
namespace DamageAssesment.Api.Responses.Services
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
2023-10-19 14:59:02 -05:00
|
|
|
|
public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
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
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 14:59:02 -05:00
|
|
|
|
public async Task<List<Survey>> getSurveysAsync(string language, string token)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-20 23:58:29 -05:00
|
|
|
|
if (!string.IsNullOrEmpty(language))
|
|
|
|
|
url = url + "/" + language;
|
2023-10-19 14:59:02 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 14:59:02 -05:00
|
|
|
|
public async Task<Survey> getSurveyAsync(int surveyId, string token)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyById"), surveyId);
|
2023-10-19 14:59:02 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
2023-10-19 14:59:02 -05:00
|
|
|
|
if (survey == null )
|
2023-08-15 22:52:30 -05:00
|
|
|
|
return null;
|
|
|
|
|
else return survey;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveyAsync()");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|