using DamageAssesment.Api.SurveyResponses.Bases; using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.SurveyResponses.Models; using Newtonsoft.Json; namespace DamageAssesment.Api.SurveyResponses.Providers { public class QuestionServiceProvider : ServiceProviderBase, IQuestionServiceProvider { public QuestionServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger logger) : base(configuration, httpUtil, logger, "/api/Questions", configuration.GetValue("EndPointSettings:QuestionUrlBase")) { } public async Task> getQuestionsAsync() { try { var url = urlBase + ressource; var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); var questions = JsonConvert.DeserializeObject>(responseJsonString); if (questions == null || !questions.Any()) return new List(); else return questions; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync()"); return new List(); } } public async Task> getSurveyQuestionsAsync(int surveyId) { try { var url = urlBase + "/api/GetSurveyQuestions/" + surveyId; var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); var questions = JsonConvert.DeserializeObject>(responseJsonString); if (questions == null || !questions.Any()) return new List() ; else return questions; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getSurveyQuestionsAsync()"); return new List(); } } public async Task getQuestionsAsync(int questionId) { try { var url = urlBase + "/api/Questions/" + questionId; var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); var question = JsonConvert.DeserializeObject(responseJsonString); if (question == null) return null; else return question; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: QuestionServiceProvider.getQuestionsAsync(questionId)"); return null; } } } }