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/12 12:04:08 UTC

[GitHub] [incubator-openwhisk-apigateway] rabbah commented on a change in pull request #335: Add paging to getTenantAPIs

rabbah commented on a change in pull request #335: Add paging to getTenantAPIs
URL: https://github.com/apache/incubator-openwhisk-apigateway/pull/335#discussion_r274875890
 
 

 ##########
 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:
   i'm not fluent in lua and did not RTM - is `for i = skip, limit` ranging from [1..n] inclusive when the `skip` query param is not defined?

----------------------------------------------------------------
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