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 { public class GetEmployeeByCode : BaseEndpoint { private readonly IEmployeeBLL _employeeBLL; public GetEmployeeByCode(IEmployeeBLL employeeBLL) { _employeeBLL = employeeBLL; } public override void Configure() { Get("/Employee/GetEmployeeByCode"); AllowAnonymous(); } public record GetEmployeeByCodeParameters( [property: QueryParam] string EmployeeCode, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync( GetEmployeeByCodeParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var employeeId = await _employeeBLL.GetEmployeeIdByCode( parameters.EmployeeCode, loginDTO ); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(employeeId, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }