From: Marcin Haba Date: Thu, 29 Jun 2023 14:25:47 +0000 (+0200) Subject: baculum: Add object categories endpoint X-Git-Tag: Release-13.0.4~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=837954005d12f72ded67a1351517b123d8db8ee3;p=thirdparty%2Fbacula.git baculum: Add object categories endpoint --- diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index 1b0146fb0..9b7b884ff 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -478,23 +478,6 @@ LEFT JOIN Client USING (ClientId) ' return $result; } - /** - * Get object categories based on criterias. - * - * @param array $criteria SQL criteria to get job list - * @return array category list or empty list if no category found - */ - public function getObjectCategories($criteria = []) { - $where = Database::getWhere($criteria); - - $sql = 'SELECT DISTINCT ObjectCategory as objectcategory -FROM Object -JOIN Job USING (JobId) ' -. $where['where']; - $statement = Database::runQuery($sql, $where['params']); - return $statement->fetchAll(\PDO::FETCH_ASSOC); - } - public function getObjectById($objectid) { $params = [ 'Object.ObjectId' => [[ @@ -754,4 +737,26 @@ JOIN Job USING (JobId) ' $values = array_keys($result); return $values; } + + /** + * Get existing object categories. + * + * @param integer $limit_val maximum number of elements to return + * @return array object names + */ + public function getObjectCategories($limit_val = null) { + $limit = ''; + if(is_int($limit_val) && $limit_val > 0) { + $limit = sprintf( + ' LIMIT %d', + $limit_val + ); + } + $sql = 'SELECT DISTINCT ObjectCategory as objectcategory + FROM Object + ORDER BY ObjectCategory ' . $limit; + $statement = Database::runQuery($sql); + $result = $statement->fetchAll(PDO::FETCH_COLUMN); + return $result; + } } diff --git a/gui/baculum/protected/API/Pages/API/ObjectCategories.php b/gui/baculum/protected/API/Pages/API/ObjectCategories.php new file mode 100644 index 000000000..acaa6ef9c --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/ObjectCategories.php @@ -0,0 +1,43 @@ + + * @category API + * @package Baculum API + */ +class ObjectCategories extends BaculumAPIServer { + + public function get() { + $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : null; + + $this->output = $this->getModule('object')->getObjectCategories( + $limit + ); + $this->error = ObjectError::ERROR_NO_ERRORS; + } +} diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index a1dabdde0..e1e4248bd 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -109,6 +109,7 @@ + diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index d3ed43572..7832d679f 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -8575,6 +8575,44 @@ ] } }, + "/api/v2/objects/categories": { + "get": { + "tags": ["objects"], + "summary": "Object categories", + "description": "Get object categories.", + "responses": { + "200": { + "description": "Object categories.", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "output": { + "type": "array", + "items": { + "type": "string", + "description": "Object category" + } + }, + "error": { + "type": "integer", + "description": "Error code", + "enum": [0, 1, 2, 3, 6, 7, 1000] + } + } + } + } + } + } + }, + "parameters": [ + { + "$ref": "#/components/parameters/Limit" + } + ] + } + }, "/api/v2/objects/types": { "get": { "tags": ["objects"],