]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add offset parameter to event and pool list endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 22 Dec 2022 15:04:50 +0000 (16:04 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 9 Jan 2023 12:34:42 +0000 (13:34 +0100)
gui/baculum/protected/API/Modules/EventManager.php
gui/baculum/protected/API/Modules/PoolManager.php
gui/baculum/protected/API/Pages/API/Events.php
gui/baculum/protected/API/Pages/API/Pools.php
gui/baculum/protected/API/openapi_baculum.json

index 491451a3053f28af10a324fb3fbf3fd3b6cc1d52..54757c8b7b2a66d6610e3173ebf36339bc65553e 100644 (file)
@@ -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']);
        }
index 2a97fc3fd21919e495823aff51968da772721e1a..0af41bf24c0b6afed95ffd73ae059b380ddeafa5 100644 (file)
@@ -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);
        }
index 3561ae71640647400dcec73e4a30bbfb9880ace6..4b33828a9d5664c0ff25b85d1c5a6f799f78ffaf 100644 (file)
@@ -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;
        }
index bc6041cfce82d8b6fff276d181bfbea935ccc77b..41aa33458ed9bbd84b0e92253c3374600e446b60 100644 (file)
@@ -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'],
index 8a3dff595b2cd6aa79ed7c8cd96a886ca87215f0..23869f955aa95e231c636b5e79bec04e006e9c44 100644 (file)
                                                }
                                        }
                                },
-                               "parameters": [{
-                                       "$ref": "#/components/parameters/Limit"
-                               }]
+                               "parameters": [
+                                       {
+                                               "$ref": "#/components/parameters/Limit"
+                                       },
+                                       {
+                                               "$ref": "#/components/parameters/Offset"
+                                       }
+                               ]
                        }
                },
                "/api/v2/pools/{poolid}": {
                                        {
                                                "$ref": "#/components/parameters/Limit"
                                        },
+                                       {
+                                               "$ref": "#/components/parameters/Offset"
+                                       },
                                        {
                                                "name": "eventscode",
                                                "in": "query",