2023-09-04 20:59:21 -05:00
|
|
|
|
using DamageAssesment.Api.SurveyResponses.Interfaces;
|
2023-08-15 22:52:30 -05:00
|
|
|
|
using DamageAssesment.Api.SurveyResponses.Models;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2023-09-04 20:59:21 -05:00
|
|
|
|
namespace DamageAssesment.Api.SurveyResponses.Services
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
public class EmployeeServiceProvider :ServiceProviderBase, IEmployeeServiceProvider
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
public EmployeeServiceProvider(IConfiguration configuration, IHttpUtil httpUtil, ILogger<EmployeeServiceProvider> logger) : base(configuration, httpUtil, logger, "/api/Employees", configuration.GetValue<string>("EndPointSettings:EmployeeUrlBase"))
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<List<Employee>> getEmployeesAsync()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var url = urlBase + ressource;
|
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var employees = JsonConvert.DeserializeObject<List<Employee>>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (employees == null || !employees.Any())
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Employee>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
else return employees;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeesAsync()");
|
2023-09-04 20:31:41 -05:00
|
|
|
|
return new List<Employee>();
|
2023-08-15 22:52:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-04 20:31:41 -05:00
|
|
|
|
public async Task<Employee> getEmployeeAsync(string employeeId)
|
2023-08-15 22:52:30 -05:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-09-04 20:31:41 -05:00
|
|
|
|
var url = urlBase + "/api/Employees/" + employeeId;
|
|
|
|
|
var responseJsonString = await httpUtil.SendAsync(HttpMethod.Get, url, null);
|
|
|
|
|
var employee = JsonConvert.DeserializeObject<Employee>(responseJsonString);
|
2023-08-15 22:52:30 -05:00
|
|
|
|
|
|
|
|
|
if (employee == null )
|
|
|
|
|
return null;
|
|
|
|
|
else return employee;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger?.LogError($"Exception Found : {ex.Message} - Ref: EmployeeServiceProvider.getEmployeeAsync()");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|