Commit d653b80b authored by Marcin Haba's avatar Marcin Haba
Browse files

baculum: Add offset parameter to event and pool list endpoint

parent 2fa22dca
......@@ -38,7 +38,7 @@ class EventManager extends APIModule {
* @param array $time_scope time range for events time
* @param int|null $limit_val limit results value
*/
public function getEvents($criteria = [], $time_scope = [], $limit_val = null) {
public function getEvents($criteria = [], $time_scope = [], $limit_val = 0, $offset_val = 0) {
$sort_col = 'EventsId';
$db_params = $this->getModule('api_config')->getConfig('db');
if ($db_params['type'] === Database::PGSQL_TYPE) {
......@@ -49,6 +49,10 @@ class EventManager extends APIModule {
if(is_int($limit_val) && $limit_val > 0) {
$limit = ' LIMIT ' . $limit_val;
}
$offset = '';
if (is_int($offset_val) && $offset_val > 0) {
$offset = ' OFFSET ' . $offset_val;
}
$where = Database::getWhere($criteria, true);
......@@ -64,7 +68,7 @@ class EventManager extends APIModule {
$where['where'] = ' WHERE ' . $where['where'];
}
$sql = 'SELECT Events.* FROM Events ' . $where['where'] . $order . $limit;
$sql = 'SELECT Events.* FROM Events ' . $where['where'] . $order . $limit . $offset;
return EventRecord::finder()->findAllBySql($sql, $where['params']);
}
......
......@@ -32,7 +32,7 @@ use Prado\Data\ActiveRecord\TActiveRecordCriteria;
* @package Baculum API
*/
class PoolManager extends APIModule {
public function getPools($limit) {
public function getPools($limit_val = 0, $offset_val = 0) {
$criteria = new TActiveRecordCriteria;
$order = 'Name';
$db_params = $this->getModule('api_config')->getConfig('db');
......@@ -40,8 +40,11 @@ class PoolManager extends APIModule {
$order = strtolower($order);
}
$criteria->OrdersBy[$order] = 'asc';
if(is_int($limit) && $limit > 0) {
$criteria->Limit = $limit;
if(is_int($limit_val) && $limit_val > 0) {
$criteria->Limit = $limit_val;
}
if (is_int($offset_val) && $offset_val > 0) {
$criteria->Offset = $offset_val;
}
return PoolRecord::finder()->findAll($criteria);
}
......
......@@ -34,6 +34,7 @@ class Events extends BaculumAPIServer {
public function get() {
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$eventscode = $this->Request->contains('eventscode') && $misc->isValidName($this->Request['eventscode']) ? $this->Request['eventscode'] : null;
$eventstype = $this->Request->contains('eventstype') && $misc->isValidName($this->Request['eventstype']) ? $this->Request['eventstype'] : null;
$eventstimestart = $this->Request->contains('eventstimestart') && $misc->isValidBDate($this->Request['eventstimestart']) ? $this->Request['eventstimestart'] : null;
......@@ -81,7 +82,7 @@ class Events extends BaculumAPIServer {
$time_scope['eventstimeend'] = $eventstimeend;
}
$events = $this->getModule('event')->getEvents($params, $time_scope, $limit);
$events = $this->getModule('event')->getEvents($params, $time_scope, $limit, $offset);
$this->output = $events;
$this->error = EventError::ERROR_NO_ERRORS;
}
......
......@@ -32,8 +32,10 @@ use Baculum\Common\Modules\Errors\PoolError;
*/
class Pools extends BaculumAPIServer {
public function get() {
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$pools = $this->getModule('pool')->getPools($limit);
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$pools = $this->getModule('pool')->getPools($limit, $offset);
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
['.pool'],
......
......@@ -2763,9 +2763,14 @@
}
}
},
"parameters": [{
"$ref": "#/components/parameters/Limit"
}]
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
}
]
}
},
"/api/v2/pools/{poolid}": {
......@@ -7242,6 +7247,9 @@
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
},
{
"name": "eventscode",
"in": "query",
......
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