Skip to content

Commit

Permalink
add non ocs getscheme endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: grnd-alt <salimbelakkaf@outlook.de>
  • Loading branch information
grnd-alt committed Jul 22, 2024
1 parent 8e059f3 commit b31c9f7
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 6 deletions.
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
['name' => 'api1#createTable', 'url' => '/api/1/tables', 'verb' => 'POST'],
['name' => 'api1#updateTable', 'url' => '/api/1/tables/{tableId}', 'verb' => 'PUT'],
['name' => 'api1#getTable', 'url' => '/api/1/tables/{tableId}', 'verb' => 'GET'],
['name' => 'api1#showScheme', 'url' => '/api/1/tables/{tableId}/scheme', 'verb' => 'GET'],
['name' => 'api1#deleteTable', 'url' => '/api/1/tables/{tableId}', 'verb' => 'DELETE'],
// -> views
['name' => 'api1#indexViews', 'url' => '/api/1/tables/{tableId}/views', 'verb' => 'GET'],
Expand Down
12 changes: 12 additions & 0 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ public function createTable(string $title, ?string $emoji, string $template = 'c
}
}

/**
* returns table scheme
* @param int $tableId
* @return \OCP\AppFramework\Http\DataResponse
*/
public function showScheme(int $tableId): DataResponse {
return $this->handleError(function () use ($tableId) {
$scheme = $this->tableService->getScheme($tableId);
return new DataResponse($scheme->jsonSerialize(), http::STATUS_OK, ["Content-Disposition" => "attachment", "filename" => $scheme->getTitle() . ".json", "Content-Type" => "application/octet-stream"]);
});
}

/**
* Get a table object
*
Expand Down
18 changes: 12 additions & 6 deletions lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

/**
* @psalm-import-type TablesTable from ResponseDefinitions
* @psalm-import-type TablesView from ResponseDefinitions
* @psalm-import-type TablesColumn from ResponseDefinitions
*/
class ApiTablesController extends AOCSController {
private TableService $service;
Expand Down Expand Up @@ -116,12 +118,16 @@ public function showScheme(int $id): DataResponse {
/**
* @NoAdminRequired
*
* @param string $title
* @param string $emoji
* @param string $description
* @param Column[] $columns
* @param View[] $views
* @return DataResponse
* creates table from scheme
*
* @param string $title title of new table
* @param string $emoji emoji
* @param string $description description
* @param array<TablesColumn > $columns columns
* @param array<TablesView> $views views
* @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* 200: Tables returned
*/
public function createFromScheme(string $title, string $emoji, string $description, array $columns, array $views): DataResponse {
try {
Expand Down
329 changes: 329 additions & 0 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -5699,6 +5699,335 @@
}
}
},
"/ocs/v2.php/apps/tables/api/2/tables/scheme/{id}": {
"get": {
"operationId": "api_tables-show-scheme",
"summary": "[api v2] Get a table Scheme",
"tags": [
"api_tables"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "id",
"in": "path",
"description": "Table 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": "Scheme 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/Table"
}
}
}
}
}
}
}
},
"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/tables/scheme": {
"post": {
"operationId": "api_tables-create-from-scheme",
"summary": "creates table from scheme",
"tags": [
"api_tables"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"title",
"emoji",
"description",
"columns",
"views"
],
"properties": {
"title": {
"type": "string",
"description": "title of new table"
},
"emoji": {
"type": "string",
"description": "emoji"
},
"description": {
"type": "string",
"description": "description"
},
"columns": {
"type": "array",
"description": "columns",
"items": {
"$ref": "#/components/schemas/Column"
}
},
"views": {
"type": "array",
"description": "views",
"items": {
"$ref": "#/components/schemas/View"
}
}
}
}
}
}
},
"parameters": [
{
"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": "Tables 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/Table"
}
}
}
}
}
}
}
},
"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"
}
}
}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/apps/tables/api/2/tables/{id}/transfer": {
"put": {
"operationId": "api_tables-transfer",
Expand Down

0 comments on commit b31c9f7

Please sign in to comment.