Commit 2fa22dca authored by Marcin Haba's avatar Marcin Haba
Browse files

baculum: Add offset parameter to storage and client list endpoint

parent 1372ab96
......@@ -33,10 +33,13 @@ use Prado\Data\ActiveRecord\TActiveRecordCriteria;
*/
class ClientManager extends APIModule {
public function getClients($limit) {
public function getClients($limit_val = 0, $offset_val = 0) {
$criteria = new TActiveRecordCriteria;
if(is_numeric($limit) && $limit > 0) {
$criteria->Limit = $limit;
if(is_numeric($limit_val) && $limit_val > 0) {
$criteria->Limit = $limit_val;
}
if (is_int($offset_val) && $offset_val > 0) {
$criteria->Offset = $offset_val;
}
return ClientRecord::finder()->findAll($criteria);
}
......
......@@ -33,10 +33,13 @@ use Prado\Data\ActiveRecord\TActiveRecordCriteria;
*/
class StorageManager extends APIModule {
public function getStorages($limit) {
public function getStorages($limit_val = 0, $offset_val = 0) {
$criteria = new TActiveRecordCriteria;
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 StorageRecord::finder()->findAll($criteria);
}
......
......@@ -33,10 +33,12 @@ use Baculum\Common\Modules\Errors\ClientError;
class Clients 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;
$result = $this->getModule('bconsole')->bconsoleCommand($this->director, array('.client'));
if ($result->exitcode === 0) {
$clients = $this->getModule('client')->getClients($limit);
$clients = $this->getModule('client')->getClients($limit, $offset);
array_shift($result->output);
$clients_output = array();
foreach($clients as $client) {
......
......@@ -33,8 +33,10 @@ use Baculum\Common\Modules\Errors\StorageError;
class Storages extends BaculumAPIServer {
public function get() {
$misc = $this->getModule('misc');
$limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
$storages = $this->getModule('storage')->getStorages($limit);
$offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
$storages = $this->getModule('storage')->getStorages($limit, $offset);
$result = $this->getModule('bconsole')->bconsoleCommand(
$this->director,
array('.storage')
......
......@@ -452,9 +452,14 @@
}
}
},
"parameters": [{
"$ref": "#/components/parameters/Limit"
}]
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
}
]
}
},
"/api/v2/clients/{clientid}": {
......@@ -2414,9 +2419,14 @@
}
}
},
"parameters": [{
"$ref": "#/components/parameters/Limit"
}]
"parameters": [
{
"$ref": "#/components/parameters/Limit"
},
{
"$ref": "#/components/parameters/Offset"
}
]
}
},
"/api/v2/storages/{storageid}": {
......
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