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

51 lines
2.0 KiB
C#
Raw Normal View History

using DamageAssesment.Api.Responses.Interfaces;
using DamageAssesment.Api.Responses.Models;
2023-08-15 22:52:30 -05:00
using Newtonsoft.Json;
namespace DamageAssesment.Api.Responses.Services
2023-08-15 22:52:30 -05:00
{
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"))
2023-08-15 22:52:30 -05:00
{
}
public async Task<List<Survey>> getSurveysAsync(string token)
2023-08-15 22:52:30 -05:00
{
try
{
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 )
return null;
else return survey;
}
catch (Exception ex)
{
logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveyAsync()");
return null;
}
}
}
}