using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Policy; using PayRollDAL.DTO.Policy; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Policy { public class SavePolicy : BaseEndpoint> { private readonly IPolicyBLL _PolicyBLL; public SavePolicy(IPolicyBLL policyBLL) { _PolicyBLL = policyBLL; } public override void Configure() { Post("/Policy/SavePolicy"); AllowAnonymous(); } public record SavePolicyParameters( [property: FromHeader] string Login, [property: FromBody] PolicyDTO PolicyDTO ); protected override string? GetCacheKey(SavePolicyParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( SavePolicyParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _PolicyBLL.SavePolicy(req.PolicyDTO, loginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }