From 7dca530f7078e7ec37dce0ee5d6fd9adf85e307b Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Mon, 29 Jul 2024 16:02:49 +0530 Subject: [PATCH] Add pagination to templates --- app/controllers/api/functions.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index d294d5e4ee..995954397a 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -2368,9 +2368,11 @@ App::get('/v1/functions/templates') ->label('sdk.response.code', Response::STATUS_CODE_OK) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_TEMPLATE_FUNCTION_LIST) + ->param('limit', 10, new Range(0, 200), 'Limit the number of templates returned in the response. Max limit: 100.', true) + ->param('offset', 0, new Range(0, 200), 'Offset the list of returned templates. Max offset: 100.', true) ->inject('response') - ->action(function (Response $response) { - $templates = Config::getParam('function-templates', []); + ->action(function (int $limit, int $offset, Response $response) { + $templates = \array_slice(Config::getParam('function-templates', []), $offset, $limit); $response->dynamic(new Document([ 'templates' => $templates, 'total' => \count($templates),