Change routes for scan-mailbox task to allow multiple tasks per user

This commit is contained in:
Eike Kettner
2020-05-21 09:00:45 +02:00
parent 743aa9d754
commit 9f9dd6c0fb
6 changed files with 213 additions and 59 deletions

View File

@ -31,6 +31,20 @@ object QUserTask {
)
).query[RPeriodicTask].stream.map(makeUserTask)
def findById(
account: AccountId,
id: Ident
): ConnectionIO[Option[UserTask[String]]] =
selectSimple(
RPeriodicTask.Columns.all,
RPeriodicTask.table,
and(
cols.group.is(account.collective),
cols.submitter.is(account.user),
cols.id.is(id)
)
).query[RPeriodicTask].option.map(_.map(makeUserTask))
def insert(account: AccountId, task: UserTask[String]): ConnectionIO[Int] =
for {
r <- task.toPeriodicTask[ConnectionIO](account)

View File

@ -42,12 +42,14 @@ trait UserTaskStore[F[_]] {
D: Decoder[A]
): Stream[F, UserTask[A]]
/** Return a user-task with the given id. */
def getByIdRaw(account: AccountId, id: Ident): OptionT[F, UserTask[String]]
/** Updates or inserts the given task.
*
* The task is identified by its id. If no task with this id
* exists, a new one is created. Otherwise the existing task is
* updated. The job executors are notified if a task has been
* enabled.
* updated.
*/
def updateTask[A](account: AccountId, ut: UserTask[A])(implicit E: Encoder[A]): F[Int]
@ -100,6 +102,9 @@ object UserTaskStore {
def getByNameRaw(account: AccountId, name: Ident): Stream[F, UserTask[String]] =
store.transact(QUserTask.findByName(account, name))
def getByIdRaw(account: AccountId, id: Ident): OptionT[F, UserTask[String]] =
OptionT(store.transact(QUserTask.findById(account, id)))
def getByName[A](account: AccountId, name: Ident)(implicit
D: Decoder[A]
): Stream[F, UserTask[A]] =