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 QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider
|
|
|
|
|
{
|
2023-09-13 00:28:24 -05:00
|
|
|
|
public QuestionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<QuestionServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Question"), configuration.GetValue<string>("EndPointSettings:QuestionUrlBase"))
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 23:32:30 -05:00
|
|
|
|
public async Task<List<Question>> getQuestionsAsync(string token)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-19 23:32:30 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (questions == null || !questions.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Question>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return questions;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Question>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-19 23:32:30 -05:00
|
|
|
|
public async Task<List<SurveyQuestions>> getSurveyQuestionsAsync(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:SurveyQuestion"), surveyId);
|
2023-09-19 23:32:30 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (questions == null || !questions.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<SurveyQuestions>() ;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return questions;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getSurveyQuestionsAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<SurveyQuestions>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2023-09-19 23:32:30 -05:00
|
|
|
|
public async Task<Question> getQuestionsAsync(int questionId, 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:QuestionById"), questionId);
|
2023-09-19 23:32:30 -05:00
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var question = JsonConvert.DeserializeObject<Question>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (question == null)
|
|
|
|
|
return null;
|
|
|
|
|
else return question;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync(questionId)");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|