Skip to content

Commit

Permalink
add a endpoint to request column objects
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Steffens <florian.steffens@nextcloud.com>
  • Loading branch information
Florian Steffens committed Oct 27, 2023
1 parent e9d06b0 commit 0df6d43
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 13 deletions.
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
['name' => 'ApiTables#update', 'url' => '/api/2/tables/{id}', 'verb' => 'PUT'],
['name' => 'ApiTables#destroy', 'url' => '/api/2/tables/{id}', 'verb' => 'DELETE'],

['name' => 'ApiColumns#index', 'url' => '/api/2/columns', 'verb' => 'GET'],
['name' => 'ApiColumns#index', 'url' => '/api/2/columns/{nodeType}/{nodeId}', 'verb' => 'GET'],
['name' => 'ApiColumns#show', 'url' => '/api/2/columns/{id}', 'verb' => 'GET'],
['name' => 'ApiColumns#createNumberColumn', 'url' => '/api/2/columns/number', 'verb' => 'POST'],
['name' => 'ApiColumns#createTextColumn', 'url' => '/api/2/columns/text', 'verb' => 'POST'],
['name' => 'ApiColumns#createSelectionColumn', 'url' => '/api/2/columns/selection', 'verb' => 'POST'],
Expand Down
24 changes: 24 additions & 0 deletions lib/Controller/ApiColumnsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ public function index(int $nodeId, string $nodeType): DataResponse {
}
}

/**
* [api v2] Get a column object
*
* @NoAdminRequired
*
* @param int $id Column ID
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Column returned
* 403: No permissions
* 404: Not found
*/
public function show(int $id): DataResponse {
try {
return new DataResponse($this->service->find($id)->jsonSerialize());
} catch (PermissionError $e) {
return $this->handlePermissionError($e);
} catch (InternalError $e) {
return $this->handleError($e);
} catch (NotFoundError $e) {
return $this->handleNotFoundError($e);
}
}

/**
* [api v2] Create new numbered column
*
Expand Down
209 changes: 197 additions & 12 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5398,7 +5398,7 @@
}
}
},
"/ocs/v2.php/apps/tables/api/2/columns": {
"/ocs/v2.php/apps/tables/api/2/columns/{nodeType}/{nodeId}": {
"get": {
"operationId": "api_columns-list",
"summary": "[api v2] Get all columns for a table or a view",
Expand All @@ -5415,19 +5415,9 @@
}
],
"parameters": [
{
"name": "nodeId",
"in": "query",
"description": "Node ID",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "nodeType",
"in": "query",
"in": "path",
"description": "Node type",
"required": true,
"schema": {
Expand All @@ -5438,6 +5428,16 @@
]
}
},
{
"name": "nodeId",
"in": "path",
"description": "Node ID",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
Expand Down Expand Up @@ -5600,6 +5600,191 @@
}
}
},
"/ocs/v2.php/apps/tables/api/2/columns/{id}": {
"get": {
"operationId": "api_columns-show",
"summary": "[api v2] Get a column object",
"tags": [
"api_columns"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"description": "Column ID",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
},
{
"name": "OCS-APIRequest",
"in": "header",
"description": "Required to be true for the API request to pass",
"required": true,
"schema": {
"type": "boolean",
"default": true
}
}
],
"responses": {
"200": {
"description": "Column returned",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"$ref": "#/components/schemas/Column"
}
}
}
}
}
}
}
},
"403": {
"description": "No permissions",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"500": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
},
"404": {
"description": "Not found",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {
"type": "object",
"required": [
"message"
],
"properties": {
"message": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/tables/api/2/columns/number": {
"post": {
"operationId": "api_columns-create-number-column",
Expand Down

0 comments on commit 0df6d43

Please sign in to comment.