using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.TimeSlip; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.TimeSlip { public class GetTimeSlip : BaseEndpoint> { private readonly ITimeSlipBLL _TimeSlipBLL; public GetTimeSlip(ITimeSlipBLL TimeSlipBLL) { _TimeSlipBLL = TimeSlipBLL; } public override void Configure() { Get("/TimeSlip/GetTimeSlip"); AllowAnonymous(); } public record GetTimeSlipParameters( [property: QueryParam] int TimeSlipId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetTimeSlipParameters GetTimeSlipParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetTimeSlipParameters.TimeSlipId!, EntityConstant.OBJECTTIMESLIP, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetTimeSlipParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _TimeSlipBLL.GetTimeSlip(parameters.TimeSlipId, 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); } } } }