using FastEndpoints; using PayRollBLL.Declaration; using PayRollDAL.DTO.Declaration; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace PayRollSL.EndPoints.Declaration { public class SaveDeclaration : BaseEndpoint { private readonly IDeclarationBLL _declarationBLL; public SaveDeclaration(IDeclarationBLL declarationBLL) { _declarationBLL = declarationBLL; } public override void Configure() { Post("/Declaration/SaveDeclaration"); AllowAnonymous(); } public record SaveDeclarationParameters( [property: FromBody] DeclarationDTO DeclarationDTO, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync( SaveDeclarationParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _declarationBLL.SaveDeclaration(parameters.DeclarationDTO, 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); } } } }