using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.ShiftPattern; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.ShiftPattern { public class GetShiftPattern : BaseEndpoint> { private readonly IShiftPatternBLL _ShiftPatternBLL; public GetShiftPattern(IShiftPatternBLL shiftPatternBLL) { _ShiftPatternBLL = shiftPatternBLL; } public override void Configure() { Get("/ShiftPattern/GetShiftPattern"); AllowAnonymous(); } public record GetShiftPatternParameters( [property: FromHeader] string Login, [property: QueryParam] int ShiftPatternId ); protected override string? GetCacheKey(GetShiftPatternParameters req, LoginDTO loginDTO) { try { return KeyGenerator.KeyGeneration(req.ShiftPatternId, EntityConstant.OBJECTSHIFTPATTERN, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync( GetShiftPatternParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _ShiftPatternBLL.GetShiftPattern(req.ShiftPatternId, 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); } } } }