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