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