using DamageAssesment.Api.Responses.Interfaces; using DamageAssesment.Api.Responses.Models; using Newtonsoft.Json; namespace DamageAssesment.Api.Responses.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(string token) { try { var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); 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, string token) { try { url = urlBase + string.Format(configuration.GetValue("RessourceSettings:SurveyById"), surveyId); var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null, token); 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; } } } }