using DamageAssesment.Api.UsersAccess.Interfaces; using DamageAssesment.Api.UsersAccess.Models; using Newtonsoft.Json; namespace DamageAssesment.Api.UsersAccess.Services { public class EmployeeServiceProvider : ServiceProviderBase, IEmployeeServiceProvider { public EmployeeServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger logger) : base(configuration, httpUtil, logger, configuration.GetValue("RessourceSettings:Employee"), configuration.GetValue("EndPointSettings:EmployeeUrlBase")) { } public async Task> getEmployeesAsync(string token) { try { var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); var employees = JsonConvert.DeserializeObject>(responseJsonString); if (employees == null || !employees.Any()) return new List(); else return employees; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()"); return new List(); } } public async Task getEmployeeAsync(int employeeId, string token) { try { url = urlBase + string.Format(configuration.GetValue("RessourceSettings:EmployeeById"), employeeId); var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null,token); var employee = JsonConvert.DeserializeObject(responseJsonString); if (employee == null) return null; else return employee; } catch (Exception ex) { logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeeAsync()"); return null; } } } }