using FastEndpoints; using AccountsBLL.Budget; using AccountsDAL.DTO.Budget; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AccountsSL.EndPoints.Budget { public class SaveBudget : BaseEndpoint> { private readonly IBudgetBLL _BudgetBLL; public SaveBudget(IBudgetBLL BudgetBLL) { _BudgetBLL = BudgetBLL; } public override void Configure() { Post("/Budget/SaveBudget"); AllowAnonymous(); } public record SaveBudgetParameters( [property: FromHeader] string Login, [property: FromBody] BudgetDTO BudgetDTO ); // Mutation endpoint -- never cached. protected override string? GetCacheKey(SaveBudgetParameters req, LoginDTO login) => null; protected override async Task> ExecuteAsync( SaveBudgetParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _BudgetBLL.SaveBudget(req.BudgetDTO, LoginDTO!, ct); 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 ); } } } }