You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2019/04/23 07:02:40 UTC
[GitHub] [incubator-openwhisk-apigateway] larandersson commented on a change
in pull request #335: Add paging to getTenantAPIs
larandersson commented on a change in pull request #335: Add paging to getTenantAPIs
URL: https://github.com/apache/incubator-openwhisk-apigateway/pull/335#discussion_r277540323
##########
File path: scripts/lua/management/lib/tenants.lua
##########
@@ -114,7 +114,39 @@ function _M.getTenantAPIs(dataStore, id, queryParams)
end
end
end
- return apiList
+ if ((queryParams['skip'] == nil and queryParams['limit'] == nil) or table.getn(apiList) == 0) then
+ return apiList
+ else
+ return applyPagingToAPIs(apiList, queryParams)
+ end
+end
+
+-- Apply paging on apis
+-- @param apis the list of apis
+-- @param queryparams object containing optional query parameters
+function applyPagingToAPIs(apiList, queryParams)
+ local skip = queryParams['skip'] == nil and 1 or queryParams['skip']
+ local limit = queryParams['limit'] == nil and table.getn(apiList) or queryParams['limit']
+ if (tonumber(limit) < 1) then
+ return {}
+ end
+ if (tonumber(skip) <= 0) then
+ skip = 1
+ else
+ skip = skip + 1
+ end
+ if ((skip + limit - 1) > table.getn(apiList)) then
+ limit = table.getn(apiList)
+ else
+ limit = skip + limit - 1
+ end
+ local apis = {}
+ local idx = 0
+ for i = skip, limit do
Review comment:
The line below takes care of that:
`local skip = queryParams['skip'] == nil and 1 or queryParams['skip']`
This line reads: If the skip parameter is undefined (nil), assign the value 1 to the skip variable, otherwise use the value of the skip parameter.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services