summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-08-04 15:41:35 +0200
committerJulien Veyssier <julien-nc@posteo.net>2023-08-09 14:58:02 +0200
commit0564bd23f2c270c389455082ef53be8d7f8a6219 (patch)
tree2f7ae749aa6e495db198ec2db45858ab940971ed /core
parentf363f1153e5dc6032c2c679cc466a4078e93bfed (diff)
downloadnextcloud-server-0564bd23f2c270c389455082ef53be8d7f8a6219.tar.gz
nextcloud-server-0564bd23f2c270c389455082ef53be8d7f8a6219.zip
feat: Add delete task API
Signed-off-by: Julius Härtl <jus@bitgrid.net> (cherry picked from commit fca1c309a025e34cc5d635766796d9e5b4f9386b) Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'core')
-rw-r--r--core/Controller/TextProcessingApiController.php30
-rw-r--r--core/routes.php1
2 files changed, 31 insertions, 0 deletions
diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php
index c713a70481c..e1d7788be27 100644
--- a/core/Controller/TextProcessingApiController.php
+++ b/core/Controller/TextProcessingApiController.php
@@ -157,6 +157,36 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController {
}
/**
+ * This endpoint allows to delete a scheduled task for a user
+ *
+ * @param int $id The id of the task
+ *
+ * @return DataResponse<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_NOT_FOUND|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
+ *
+ * 200: Task returned
+ * 404: Task not found
+ */
+ #[NoAdminRequired]
+ public function deleteTask(int $id): DataResponse {
+ try {
+ $task = $this->textProcessingManager->getUserTask($id, $this->userId);
+
+ $this->textProcessingManager->deleteTask($task);
+
+ $json = $task->jsonSerialize();
+
+ return new DataResponse([
+ 'task' => $json,
+ ]);
+ } catch (NotFoundException $e) {
+ return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND);
+ } catch (\RuntimeException $e) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
+ }
+ }
+
+
+ /**
* This endpoint returns a list of tasks of a user that are related
* with a specific appId and optionally with an identifier
*
diff --git a/core/routes.php b/core/routes.php
index 90578ee6f0d..ad8638e0b1e 100644
--- a/core/routes.php
+++ b/core/routes.php
@@ -149,6 +149,7 @@ $application->registerRoutes($this, [
['root' => '/textprocessing', 'name' => 'TextProcessingApi#taskTypes', 'url' => '/tasktypes', 'verb' => 'GET'],
['root' => '/textprocessing', 'name' => 'TextProcessingApi#schedule', 'url' => '/schedule', 'verb' => 'POST'],
['root' => '/textprocessing', 'name' => 'TextProcessingApi#getTask', 'url' => '/task/{id}', 'verb' => 'GET'],
+ ['root' => '/textprocessing', 'name' => 'TextProcessingApi#deleteTask', 'url' => '/task/{id}', 'verb' => 'DELETE'],
['root' => '/textprocessing', 'name' => 'TextProcessingApi#listTasksByApp', 'url' => '/tasks/app/{appId}', 'verb' => 'GET'],
],
]);