using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Leave; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Leave { public class GetLeave : BaseEndpoint> { private readonly ILeaveBLL _LeaveBLL; public GetLeave(ILeaveBLL ILeaveBLL) { _LeaveBLL = ILeaveBLL; } public override void Configure() { Get("/Leave/GetLeave"); AllowAnonymous(); } public record GetLeaveParameters( [property: QueryParam] int LeaveId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetLeaveParameters GetLeaveParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetLeaveParameters.LeaveId!, EntityConstant.OBJECTLEAVE, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetLeaveParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _LeaveBLL.GetLeave(req.LeaveId, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500); } } } }