From 58a319b66c6fcb0c419d34e9d4040f8e4a2cd5cd Mon Sep 17 00:00:00 2001 From: eshmeshek Date: Thu, 18 Dec 2025 14:50:33 +0300 Subject: [PATCH] modified: backend/src/controllers/dynamicApiController.ts modified: backend/src/controllers/endpointController.ts new file: backend/src/migrations/007_add_detailed_response.sql modified: frontend/src/components/EndpointModal.tsx modified: frontend/src/types/index.ts --- backend/src/controllers/dynamicApiController.ts | 16 ++++++++++------ backend/src/controllers/endpointController.ts | 11 ++++++++--- .../src/migrations/007_add_detailed_response.sql | 8 ++++++++ frontend/src/components/EndpointModal.tsx | 14 +++++++++++++- frontend/src/types/index.ts | 2 ++ 5 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 backend/src/migrations/007_add_detailed_response.sql diff --git a/backend/src/controllers/dynamicApiController.ts b/backend/src/controllers/dynamicApiController.ts index 2e1a57e..a50253e 100644 --- a/backend/src/controllers/dynamicApiController.ts +++ b/backend/src/controllers/dynamicApiController.ts @@ -233,12 +233,16 @@ export const executeDynamicEndpoint = async (req: ApiKeyRequest, res: Response) ); } - const responseData = { - success: true, - data: result.rows, - rowCount: result.rowCount, - executionTime: result.executionTime, - }; + // Build response based on detailed_response flag + const detailedResponse = endpoint.detailed_response || false; + const responseData = detailedResponse + ? { + success: true, + data: result.rows, + rowCount: result.rowCount, + executionTime: result.executionTime, + } + : result.rows; // Log if needed if (shouldLog && endpointId) { diff --git a/backend/src/controllers/endpointController.ts b/backend/src/controllers/endpointController.ts index 3c44800..9e80497 100644 --- a/backend/src/controllers/endpointController.ts +++ b/backend/src/controllers/endpointController.ts @@ -85,6 +85,7 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => { aql_endpoint, aql_body, aql_query_params, + detailed_response, } = req.body; if (!name || !method || !path) { @@ -119,9 +120,9 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => { name, description, method, path, database_id, sql_query, parameters, folder_id, user_id, is_public, enable_logging, execution_type, script_language, script_code, script_queries, - aql_method, aql_endpoint, aql_body, aql_query_params + aql_method, aql_endpoint, aql_body, aql_query_params, detailed_response ) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20) RETURNING *`, [ name, @@ -143,6 +144,7 @@ export const createEndpoint = async (req: AuthRequest, res: Response) => { aql_endpoint || null, aql_body || null, JSON.stringify(aql_query_params || {}), + detailed_response || false, ] ); @@ -178,6 +180,7 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => { aql_endpoint, aql_body, aql_query_params, + detailed_response, } = req.body; const result = await mainPool.query( @@ -200,8 +203,9 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => { aql_endpoint = $16, aql_body = $17, aql_query_params = $18, + detailed_response = $19, updated_at = CURRENT_TIMESTAMP - WHERE id = $19 + WHERE id = $20 RETURNING *`, [ name, @@ -222,6 +226,7 @@ export const updateEndpoint = async (req: AuthRequest, res: Response) => { aql_endpoint || null, aql_body || null, aql_query_params ? JSON.stringify(aql_query_params) : null, + detailed_response || false, id, ] ); diff --git a/backend/src/migrations/007_add_detailed_response.sql b/backend/src/migrations/007_add_detailed_response.sql new file mode 100644 index 0000000..ebee2d8 --- /dev/null +++ b/backend/src/migrations/007_add_detailed_response.sql @@ -0,0 +1,8 @@ +-- Add detailed_response flag to endpoints +-- When false (default): returns only data array +-- When true: returns full response with success, data, rowCount, executionTime + +ALTER TABLE endpoints +ADD COLUMN IF NOT EXISTS detailed_response BOOLEAN DEFAULT false; + +COMMENT ON COLUMN endpoints.detailed_response IS 'If true, returns detailed response with rowCount and executionTime. Default returns only data array.'; diff --git a/frontend/src/components/EndpointModal.tsx b/frontend/src/components/EndpointModal.tsx index bdf93d7..171fe5e 100644 --- a/frontend/src/components/EndpointModal.tsx +++ b/frontend/src/components/EndpointModal.tsx @@ -41,6 +41,8 @@ export default function EndpointModal({ aql_endpoint: endpoint?.aql_endpoint || '', aql_body: endpoint?.aql_body || '', aql_query_params: endpoint?.aql_query_params || {}, + // Response format + detailed_response: endpoint?.detailed_response || false, }); const [editingQueryIndex, setEditingQueryIndex] = useState(null); @@ -592,7 +594,7 @@ export default function EndpointModal({ )} -
+
+ +
{formData.parameters.length > 0 && ( diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.ts index 0f06cda..cc1007d 100644 --- a/frontend/src/types/index.ts +++ b/frontend/src/types/index.ts @@ -78,6 +78,8 @@ export interface Endpoint { aql_endpoint?: string; aql_body?: string; aql_query_params?: Record; + // Response format + detailed_response?: boolean; created_at: string; updated_at: string; }