aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2024-05-10 07:08:31 +0200
committerMarcel Klehr <mklehr@gmx.net>2024-05-14 11:38:41 +0200
commita8afa7f23d8bf0c1fdb1725669ff9d8d6b5ebebb (patch)
treebcd8ed95ef948cdcd9e5e99d6090ea4b27a891f8 /core/Controller
parentf3a88f04ecb19da81cb53fb95f92a673a6892310 (diff)
downloadnextcloud-server-a8afa7f23d8bf0c1fdb1725669ff9d8d6b5ebebb.tar.gz
nextcloud-server-a8afa7f23d8bf0c1fdb1725669ff9d8d6b5ebebb.zip
fix(OCS-API): Add endpoint to list user tasks
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'core/Controller')
-rw-r--r--core/Controller/TaskProcessingApiController.php36
1 files changed, 33 insertions, 3 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php
index c44764d83d5..ce89ebd34bb 100644
--- a/core/Controller/TaskProcessingApiController.php
+++ b/core/Controller/TaskProcessingApiController.php
@@ -201,16 +201,46 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController {
* with a specific appId and optionally with an identifier
*
* @param string $appId ID of the app
- * @param string|null $identifier An arbitrary identifier for the task
+ * @param string|null $customId An arbitrary identifier for the task
* @return DataResponse<Http::STATUS_OK, array{tasks: CoreTaskProcessingTask[]}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* 200: Task list returned
*/
#[NoAdminRequired]
#[ApiRoute(verb: 'GET', url: '/tasks/app/{appId}', root: '/taskprocessing')]
- public function listTasksByApp(string $appId, ?string $identifier = null): DataResponse {
+ public function listTasksByApp(string $appId, ?string $customId = null): DataResponse {
try {
- $tasks = $this->taskProcessingManager->getUserTasksByApp($this->userId, $appId, $identifier);
+ $tasks = $this->taskProcessingManager->getUserTasksByApp($this->userId, $appId, $customId);
+ /** @var CoreTaskProcessingTask[] $json */
+ $json = array_map(static function (Task $task) {
+ return $task->jsonSerialize();
+ }, $tasks);
+
+ return new DataResponse([
+ 'tasks' => $json,
+ ]);
+ } catch (Exception $e) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
+ } catch (\JsonException $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
+ *
+ * @param string|null $taskType The task type to filter by
+ * @param string|null $customId An arbitrary identifier for the task
+ * @return DataResponse<Http::STATUS_OK, array{tasks: CoreTaskProcessingTask[]}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
+ *
+ * 200: Task list returned
+ */
+ #[NoAdminRequired]
+ #[ApiRoute(verb: 'GET', url: '/tasks', root: '/taskprocessing')]
+ public function listTasksByUser(?string $taskType, ?string $customId = null): DataResponse {
+ try {
+ $tasks = $this->taskProcessingManager->getUserTasks($this->userId, $taskType, $customId);
/** @var CoreTaskProcessingTask[] $json */
$json = array_map(static function (Task $task) {
return $task->jsonSerialize();