aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/TextProcessing
diff options
context:
space:
mode:
authorJulien Veyssier <julien-nc@posteo.net>2023-08-02 16:47:41 +0200
committerJulien Veyssier <julien-nc@posteo.net>2023-08-07 13:27:53 +0200
commit9986e02097e5c82e1bb21ba3f897b14d82a50c15 (patch)
tree5210b08607f7e841b9864ffbea153e4ee5b54026 /lib/private/TextProcessing
parentb4a3f8088ab4ccb53c25ee316fe9b575b41b36f8 (diff)
downloadnextcloud-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 'lib/private/TextProcessing')
-rw-r--r--lib/private/TextProcessing/Db/TaskMapper.php19
-rw-r--r--lib/private/TextProcessing/Manager.php19
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/private/TextProcessing/Db/TaskMapper.php b/lib/private/TextProcessing/Db/TaskMapper.php
index 624efd042f7..cf78006d6d9 100644
--- a/lib/private/TextProcessing/Db/TaskMapper.php
+++ b/lib/private/TextProcessing/Db/TaskMapper.php
@@ -60,6 +60,25 @@ class TaskMapper extends QBMapper {
}
/**
+ * @param string $userId
+ * @param string $appId
+ * @param string|null $identifier
+ * @return array
+ * @throws Exception
+ */
+ public function findByApp(string $userId, string $appId, ?string $identifier = null): array {
+ $qb = $this->db->getQueryBuilder();
+ $qb->select(Task::$columns)
+ ->from($this->tableName)
+ ->where($qb->expr()->eq('app_id', $qb->createPositionalParameter($appId)))
+ ->andWhere($qb->expr()->eq('user_id', $qb->createPositionalParameter($userId)));
+ if ($identifier !== null) {
+ $qb->andWhere($qb->expr()->eq('identifier', $qb->createPositionalParameter($identifier)));
+ }
+ return $this->findEntities($qb);
+ }
+
+ /**
* @param int $timeout
* @return int the number of deleted tasks
* @throws Exception
diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php
index 05e046a0049..da38dc876a7 100644
--- a/lib/private/TextProcessing/Manager.php
+++ b/lib/private/TextProcessing/Manager.php
@@ -192,7 +192,24 @@ class Manager implements IManager {
} catch (MultipleObjectsReturnedException $e) {
throw new RuntimeException('Could not uniquely identify task with given id', 0, $e);
} catch (Exception $e) {
- throw new RuntimeException('Failure while trying to find task by id: '.$e->getMessage(), 0, $e);
+ throw new RuntimeException('Failure while trying to find task by id: ' . $e->getMessage(), 0, $e);
+ }
+ }
+
+ /**
+ * @param string $userId
+ * @param string $appId
+ * @param string|null $identifier
+ * @return array
+ */
+ public function getTasksByApp(string $userId, string $appId, ?string $identifier = null): array {
+ try {
+ $taskEntities = $this->taskMapper->findByApp($userId, $appId, $identifier);
+ return array_map(static function (DbTask $taskEntity) {
+ return $taskEntity->toPublicTask();
+ }, $taskEntities);
+ } catch (Exception $e) {
+ throw new RuntimeException('Failure while trying to find tasks by appId and identifier: ' . $e->getMessage(), 0, $e);
}
}
}