using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using PayRollBLL.Advance; using PayRollBLL.Leave; using PayRollDAL.CustomeCode.Advance; using PayRollDAL.DTO.Advance; using PayRollDAL.DTO.Leave; using PayRollSL.EndPoints.Leave; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Advance { public class SaveAdvance : BaseEndpoint> { private readonly IAdvanceBLL _AdvanceBLL; public SaveAdvance(IAdvanceBLL _IAdvanceBLL) { _AdvanceBLL = _IAdvanceBLL; } public override void Configure() { Post("/Advance/SaveAdvance"); AllowAnonymous(); } public record SaveAdvanceParameters( [property: FromHeader] string Login, [property: FromBody] AdvanceDTO AdvanceDTO ); protected override string? GetCacheKey(SaveAdvanceParameters req, LoginDTO LoginDTO) { return KeyGenerator.KeyGeneration(req.AdvanceDTO.AdvanceId, EntityConstant.OBJECTADVANCE, CacheKeyLevel.USER_LEVEL, LoginDTO); } protected override bool ShouldInvalidateCache(SaveAdvanceParameters req, LoginDTO LoginDTO) => true; protected override async Task> ExecuteAsync(SaveAdvanceParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _AdvanceBLL.SaveAdvance(req.AdvanceDTO, 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); } } } }