diff --git a/appinfo/routes.php b/appinfo/routes.php index da22566e5..b3d285cf7 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -132,6 +132,7 @@ ['name' => 'Context#show', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'GET'], ['name' => 'Context#create', 'url' => '/api/2/contexts', 'verb' => 'POST'], ['name' => 'Context#update', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'PUT'], + ['name' => 'Context#destroy', 'url' => '/api/2/contexts/{contextId}', 'verb' => 'DELETE'], ['name' => 'Context#transfer', 'url' => '/api/2/contexts/{contextId}/transfer', 'verb' => 'PUT'], ['name' => 'Context#addNode', 'url' => '/api/2/contexts/{contextId}/nodes', 'verb' => 'POST'], ['name' => 'Context#removeNode', 'url' => '/api/2/contexts/{contextId}/nodes/{nodeRelId}', 'verb' => 'DELETE'], diff --git a/lib/Controller/ContextController.php b/lib/Controller/ContextController.php index bd71417a1..a6bc51521 100644 --- a/lib/Controller/ContextController.php +++ b/lib/Controller/ContextController.php @@ -137,6 +137,29 @@ public function update(int $contextId, ?string $name, ?string $iconName, ?string } } + /** + * [api v2] Delete an existing context and return it + * + * @param int $contextId ID of the context + * @return DataResponse|DataResponse + * + * 200: returning the full context information + * 403: No permissions + * 404: Not found + * + * @NoAdminRequired + * @CanManageContext + */ + public function destroy(int $contextId): DataResponse { + try { + return new DataResponse($this->contextService->delete($contextId, $this->userId)->jsonSerialize()); + } catch (Exception $e) { + return $this->handleError($e); + } catch (NotFoundError $e) { + return $this->handleNotFoundError($e); + } + } + /** * [api v2] Transfer the ownership of a context and return it * diff --git a/lib/Service/ContextService.php b/lib/Service/ContextService.php index ee31cc7ad..e7f8993c1 100644 --- a/lib/Service/ContextService.php +++ b/lib/Service/ContextService.php @@ -206,6 +206,15 @@ public function update(int $contextId, string $userId, ?string $name, ?string $i return $context; } + /** + * @throws NotFoundError + * @throws Exception + */ + public function delete(int $contextId, string $userId): Context { + $context = $this->contextMapper->findById($contextId, $userId); + return $this->contextMapper->delete($context); + } + /** * @throws MultipleObjectsReturnedException * @throws DoesNotExistException diff --git a/openapi.json b/openapi.json index b6af3bbf1..5a96f7ff9 100644 --- a/openapi.json +++ b/openapi.json @@ -8475,6 +8475,151 @@ } } } + }, + "delete": { + "operationId": "context-destroy", + "summary": "[api v2] Delete an existing context and return it", + "tags": [ + "context" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "contextId", + "in": "path", + "description": "ID of the context", + "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": "returning the full context information", + "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/Context" + } + } + } + } + } + } + } + }, + "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/contexts/{contextId}/transfer": { diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 96936503a..236c7d17d 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -205,6 +205,8 @@ export type paths = { get: operations["context-show"]; /** [api v2] Update an existing context and return it */ put: operations["context-update"]; + /** [api v2] Delete an existing context and return it */ + delete: operations["context-destroy"]; }; "/ocs/v2.php/apps/tables/api/2/contexts/{contextId}/transfer": { /** [api v2] Transfer the ownership of a context and return it */ @@ -3164,6 +3166,57 @@ export type operations = { }; }; }; + /** [api v2] Delete an existing context and return it */ + "context-destroy": { + parameters: { + header: { + /** @description Required to be true for the API request to pass */ + "OCS-APIRequest": boolean; + }; + path: { + /** @description ID of the context */ + contextId: number; + }; + }; + responses: { + /** @description returning the full context information */ + 200: { + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: components["schemas"]["Context"]; + }; + }; + }; + }; + /** @description Not found */ + 404: { + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + message: string; + }; + }; + }; + }; + }; + 500: { + content: { + "application/json": { + ocs: { + meta: components["schemas"]["OCSMeta"]; + data: { + message: string; + }; + }; + }; + }; + }; + }; + }; /** [api v2] Transfer the ownership of a context and return it */ "context-transfer": { parameters: {