diff options
author | Julien Veyssier <julien-nc@posteo.net> | 2023-08-02 16:47:41 +0200 |
---|---|---|
committer | Julien Veyssier <julien-nc@posteo.net> | 2023-08-07 13:27:53 +0200 |
commit | 9986e02097e5c82e1bb21ba3f897b14d82a50c15 (patch) | |
tree | 5210b08607f7e841b9864ffbea153e4ee5b54026 /core | |
parent | b4a3f8088ab4ccb53c25ee316fe9b575b41b36f8 (diff) | |
download | nextcloud-server-9986e02097e5c82e1bb21ba3f897b14d82a50c15.tar.gz nextcloud-server-9986e02097e5c82e1bb21ba3f897b14d82a50c15.zip |
start implementing ocs endpoint to get task list from user+appId+identifier
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/TextProcessingApiController.php | 32 | ||||
-rw-r--r-- | core/routes.php | 1 |
2 files changed, 33 insertions, 0 deletions
diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php index 122595bb151..21cf9d58c33 100644 --- a/core/Controller/TextProcessingApiController.php +++ b/core/Controller/TextProcessingApiController.php @@ -157,4 +157,36 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController { return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); } } + + /** + * This endpoint returns a list of tasks related with a specific appId and identifier + * + * @PublicPage + * @UserRateThrottle(limit=20, period=120) + * + * @param string $appId + * @param string|null $identifier + * @return DataResponse<Http::STATUS_OK, array{tasks: array{CoreTextProcessingTask}}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}> + * + * 200: Task list returned + */ + public function listTasksByApp(string $appId, ?string $identifier = null): DataResponse { + if ($this->userId === null) { + return new DataResponse([ + 'tasks' => [], + ]); + } + try { + $tasks = $this->languageModelManager->getTasksByApp($this->userId, $appId, $identifier); + $json = array_map(static function (Task $task) { + return $task->jsonSerialize(); + }, $tasks); + + return new DataResponse([ + 'tasks' => $json, + ]); + } catch (\RuntimeException $e) { + return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); + } + } } diff --git a/core/routes.php b/core/routes.php index 4790f32af32..90578ee6f0d 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#listTasksByApp', 'url' => '/tasks/app/{appId}', 'verb' => 'GET'], ], ]); |