using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Employee; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Employee { // GB4 parity: Employee.svc.cs GetDifferenceFromJoiningDate // (WCF UriTemplate: /Get/Difference/From/JoiningDate/?EmployeeId={EmployeeId}&SeparationDate={SeparationDate}) public class GetDifferenceFromJoiningDate : BaseEndpoint> { private readonly IEmployeeBLL _EmployeeBLL; public GetDifferenceFromJoiningDate(IEmployeeBLL EmployeeBLL) { _EmployeeBLL = EmployeeBLL; } public override void Configure() { Get("/Employee/GetDifferenceFromJoiningDate"); AllowAnonymous(); } public record GetDifferenceFromJoiningDateParameters( [property: QueryParam] int EmployeeId, [property: QueryParam] string SeparationDate, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync(GetDifferenceFromJoiningDateParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var (years, months, days) = await _EmployeeBLL.GetDifferenceFromJoiningDate(req.EmployeeId, req.SeparationDate, LoginDTO!); var result = new { SeparationYears = years, SeparationMonths = months, SeparationDays = days }; return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }