chg: [brood:queryIndex] Added support of pagination and filtering

develop-unstable
Sami Mokaddem 2023-02-13 15:39:03 +01:00
parent b9292473de
commit 3fcb58c081
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
2 changed files with 10 additions and 5 deletions

View File

@ -101,8 +101,14 @@ class BroodsController extends AppController
if (!in_array($scope, $validScopes)) {
throw new MethodNotAllowedException(__('Invalid scope. Valid options are: {0}', implode(', ', $validScopes)));
}
$filter = $this->request->getQuery('quickFilter');
$data = $this->Broods->queryIndex($id, $scope, $filter, true);
$filtering = [
'page' => $this->request->getQuery('page', 1),
'limit' => $this->request->getQuery('limit', 20),
];
if (!empty($this->request->getQuery('quickFilter'))) {
$filtering['quickFilter'] = $this->request->getQuery('quickFilter');
}
$data = $this->Broods->queryIndex($id, $scope, $filtering, true);
if (!is_array($data)) {
$data = [];
}

View File

@ -151,11 +151,10 @@ class BroodsTable extends AppTable
if (empty($brood)) {
throw new NotFoundException(__('Brood not found'));
}
$filterQuery = empty($filter) ? '' : '?quickFilter=' . urlencode($filter);
if (!empty($full)) {
$filterQuery .= (empty($filterQuery) ? '?' : '&') . 'full=1';
$filter['full'] = 1;
}
$response = $this->HTTPClientGET(sprintf('/%s/index.json%s', $scope, $filterQuery), $brood);
$response = $this->HTTPClientGET(sprintf('/%s/index.json?%s', $scope, http_build_query($filter)), $brood);
if ($response->isOk()) {
return $response->getJson();
} else {