using FastEndpoints; using PayRollBLL.Declaration; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; using System.Threading; using System.Threading.Tasks; namespace PayRollSL.EndPoints.Declaration { public class DeleteDeclaration : BaseEndpoint> { private readonly IDeclarationBLL _declarationBLL; public DeleteDeclaration(IDeclarationBLL declarationBLL) { _declarationBLL = declarationBLL; } public override void Configure() { Delete("/Declaration/DeleteDeclaration"); AllowAnonymous(); } public record DeleteDeclarationParameters( [property: FromHeader] string Login, [property: QueryParam] int DeclarationId ); protected override async Task> ExecuteAsync( DeleteDeclarationParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _declarationBLL.DeleteDeclaration(req.DeclarationId, 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 ); } } } }