Commit e831b272 authored by Karamel's avatar Karamel
Browse files

Add pagination to /api/ticket/search route.

parent e60cf647
......@@ -46,6 +46,16 @@ $app->GET('/api/ticket/search', function ($request, $response, $args) {
: $queryParams['user'];
$customerId = (empty($queryParams['customer'])) ? null
: $queryParams['customer'];
$offset = (empty($queryParams['offset'])) ? null
: intval($queryParams['offset']);
if ($offset === 0) {
$offset = null;
}
$limit = (empty($queryParams['limit'])) ? null
: intval($queryParams['limit']);
if ($limit === 0) {
$limit = null;
}
// Search criterias
if ($dateStart === false) {
return $response->withApiResult(APIResult::reject('Invalid dateStart'));
......@@ -102,7 +112,12 @@ $app->GET('/api/ticket/search', function ($request, $response, $args) {
if ($customer !== null) {
$conditions[] = new DAOCondition('customer', '=', $customer);
}
$tktRes = APICaller::run($ptApp, 'ticket', 'search', [$conditions]);
if (!empty($queryParams['count'])) {
$tktRes = APICaller::run($ptApp, 'ticket', 'count', [$conditions]);
} else {
$tktRes = APICaller::run($ptApp, 'ticket', 'search',
[$conditions, $limit, $offset]);
}
return $response->withApiResult($tktRes);
});
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment