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

53 lines
2.1 KiB
C#
Raw Permalink Normal View History

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
{
public class SurveyServiceProvider : ServiceProviderBase, ISurveyServiceProvider
2023-08-15 22:52:30 -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(string language, string token)
2023-08-15 22:52:30 -05:00
{
try
{
if (!string.IsNullOrEmpty(language))
url = url + "/" + language;
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
var surveys = JsonConvert.DeserializeObject<List<Survey>>(responseJsonString);
2023-08-15 22:52:30 -05:00
if (surveys == null || !surveys.Any())
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()");
return new List<Survey>();
2023-08-15 22:52:30 -05:00
}
}
public async Task<Survey> getSurveyAsync(int surveyId, string token)
2023-08-15 22:52:30 -05:00
{
try
{
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyById"), surveyId);
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
var survey = JsonConvert.DeserializeObject<Survey>(responseJsonString);
2023-08-15 22:52:30 -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;
}
}
}
}