using GB5Shared.GOP.GBQueryExecutor; using GB5Shared.GOP.GBQueryExecutor.Models; using GB5Shared.GOP.GBQueryExecutor.DTOs; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.GOP.GBQueryExecutor { // ───────────────────────────────────────────────────────────────────── // ValidateGBConfiguredQuery — POST /GBQueryExecutor/ValidateGBConfiguredQuery // // Runs the 6-rule safety check (SELECT-only AST, @TenantId presence, etc.) // against the stored SqlTemplate and sets IsValidated = 1 on success. // // Returns 200 with a success message on pass. // Returns 500 with the validation error list on fail. // // Cache: NOT_REQUIRED — this is a mutation (marks IsValidated). // ───────────────────────────────────────────────────────────────────── public class ValidateGBConfiguredQuery : BaseEndpoint> { private readonly IGBConfiguredQueryBLL _Bll; public ValidateGBConfiguredQuery(IGBConfiguredQueryBLL bll) => _Bll = bll; public override void Configure() { Post("/GBQueryExecutor/ValidateGBConfiguredQuery"); AllowAnonymous(); } public record Params( [property: FromHeader] string Login, [property: QueryParam] int ConfiguredQueryId ); // Write endpoint — no caching protected override string? GetCacheKey(Params req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _Bll.ValidateConfiguredQuery(req.ConfiguredQueryId, 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); } } } }