Skip to content

Commit

Permalink
Fix directus#1638 [Support of offset and limit for /collections endpo…
Browse files Browse the repository at this point in the history
…int (directus#1709)
  • Loading branch information
binal-7span authored Jan 30, 2020
1 parent e73d3d4 commit 1d5fd80
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/endpoints/Collections.php
Original file line number Diff line number Diff line change
@@ -54,9 +54,24 @@ public function create(Request $request, Response $response)
public function all(Request $request, Response $response)
{
$params = $request->getQueryParams();

// directus_collections only contains user collections and the core collections will be merged atter the process of fetching data from DB. Offset and limit will apply only for user generated collections[DB] and then the core collection will getting merged. Thus, it should handled from PHP instead of DB.
if (isset($params['offset'])) {
$offset = $params['offset'];
unset($params['offset']);
}
if (isset($params['limit'])) {
$limit = $params['limit'];
unset($params['limit']);
}
$service = new TablesService($this->container);
$responseData = $service->findAll($params);

if (isset($offset) && isset($limit)) {
$responseData['data'] = array_slice($responseData['data'], $offset, $limit);
if (isset($responseData['meta']) && isset($responseData['meta']['result_count'])) {
$responseData['meta']['result_count'] = count($responseData['data']);
}
}
return $this->responseWithData($request, $response, $responseData);
}

0 comments on commit 1d5fd80

Please sign in to comment.