71 lines
2.9 KiB
C#
71 lines
2.9 KiB
C#
using DamageAssesment.Api.Responses.Interfaces;
|
|
using DamageAssesment.Api.Responses.Models;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace DamageAssesment.Api.Responses.Services
|
|
{
|
|
public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider
|
|
{
|
|
public QuestionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<QuestionServiceProvider> logger) : base(configuration, httpUtil, logger, configuration.GetValue<string>("RessourceSettings:Question"), configuration.GetValue<string>("EndPointSettings:QuestionUrlBase"))
|
|
{
|
|
}
|
|
|
|
public async Task<List<Question>> getQuestionsAsync(string token)
|
|
{
|
|
try
|
|
{
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token);
|
|
var questions = JsonConvert.DeserializeObject<List<Question>>(responseJsonString);
|
|
|
|
if (questions == null || !questions.Any())
|
|
return new List<Question>();
|
|
else return questions;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync()");
|
|
return new List<Question>();
|
|
}
|
|
}
|
|
|
|
public async Task<List<SurveyQuestions>> getSurveyQuestionsAsync(int surveyId, string token)
|
|
{
|
|
try
|
|
{
|
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:SurveyQuestion"), surveyId);
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
|
var questions = JsonConvert.DeserializeObject<List<SurveyQuestions>>(responseJsonString);
|
|
|
|
if (questions == null || !questions.Any())
|
|
return new List<SurveyQuestions>() ;
|
|
else return questions;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getSurveyQuestionsAsync()");
|
|
return new List<SurveyQuestions>();
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<Question> getQuestionsAsync(int questionId, string token)
|
|
{
|
|
try
|
|
{
|
|
url = urlBase + string.Format(configuration.GetValue<string>("RessourceSettings:QuestionById"), questionId);
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token);
|
|
var question = JsonConvert.DeserializeObject<Question>(responseJsonString);
|
|
|
|
if (question == null)
|
|
return null;
|
|
else return question;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync(questionId)");
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
}
|