using DamageAssesment.Api.SurveyResponses.Interfaces; using DamageAssesment.Api.SurveyResponses.Models; using Newtonsoft.Json; namespace DamageAssesment.Api.SurveyResponses.Services { public class SurveyServiceProvider :ServiceProviderBase, ISurveyServiceProvider { public SurveyServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger logger) : base(configuration, httpUtil, logger, configuration.GetValue("RessourceSettings:Survey"), configuration.GetValue("EndPointSettings:SurveyUrlBase")) { } public async Task> getSurveysAsync() { try { var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); var surveys = JsonConvert.DeserializeObject>(responseJsonString); if (surveys == null || !surveys.Any()) return new List(); else return surveys; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveysAsync()"); return new List(); } } public async Task getSurveyAsync(int surveyId) { try { url = urlBase + string.Format(configuration.GetValue("RessourceSettings:SurveyById"), surveyId); var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null); var survey = JsonConvert.DeserializeObject(responseJsonString); if (survey == null ) return null; else return survey; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: SurveyServiceProvider.getSurveyAsync()"); return null; } } } }