mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 10:28:27 +00:00
Starting with mail functionality
This commit is contained in:
@ -23,6 +23,7 @@ trait BackendApp[F[_]] {
|
||||
def node: ONode[F]
|
||||
def job: OJob[F]
|
||||
def item: OItem[F]
|
||||
def mail: OMail[F]
|
||||
}
|
||||
|
||||
object BackendApp {
|
||||
@ -45,6 +46,7 @@ object BackendApp {
|
||||
nodeImpl <- ONode(store)
|
||||
jobImpl <- OJob(store, httpClientEc)
|
||||
itemImpl <- OItem(store)
|
||||
mailImpl <- OMail(store)
|
||||
} yield new BackendApp[F] {
|
||||
val login: Login[F] = loginImpl
|
||||
val signup: OSignup[F] = signupImpl
|
||||
@ -57,6 +59,7 @@ object BackendApp {
|
||||
val node = nodeImpl
|
||||
val job = jobImpl
|
||||
val item = itemImpl
|
||||
val mail = mailImpl
|
||||
}
|
||||
|
||||
def apply[F[_]: ConcurrentEffect: ContextShift](
|
||||
|
@ -0,0 +1,43 @@
|
||||
package docspell.backend.ops
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import cats.data.OptionT
|
||||
import docspell.common._
|
||||
import docspell.store._
|
||||
import docspell.store.records.RUserEmail
|
||||
|
||||
trait OMail[F[_]] {
|
||||
|
||||
def getSettings(accId: AccountId, nameQ: Option[String]): F[Vector[RUserEmail]]
|
||||
|
||||
def createSettings(data: F[RUserEmail]): F[AddResult]
|
||||
|
||||
def updateSettings(accId: AccountId, name: Ident, data: RUserEmail): F[Int]
|
||||
}
|
||||
|
||||
object OMail {
|
||||
|
||||
def apply[F[_]: Effect](store: Store[F]): Resource[F, OMail[F]] =
|
||||
Resource.pure(new OMail[F] {
|
||||
def getSettings(accId: AccountId, nameQ: Option[String]): F[Vector[RUserEmail]] =
|
||||
store.transact(RUserEmail.findByAccount(accId, nameQ))
|
||||
|
||||
def createSettings(data: F[RUserEmail]): F[AddResult] =
|
||||
for {
|
||||
ru <- data
|
||||
ins = RUserEmail.insert(ru)
|
||||
exists = RUserEmail.exists(ru.uid, ru.name)
|
||||
ar <- store.add(ins, exists)
|
||||
} yield ar
|
||||
|
||||
def updateSettings(accId: AccountId, name: Ident, data: RUserEmail): F[Int] = {
|
||||
val op = for {
|
||||
um <- OptionT(RUserEmail.getByName(accId, name))
|
||||
n <- OptionT.liftF(RUserEmail.update(um.id, data))
|
||||
} yield n
|
||||
|
||||
store.transact(op.value).map(_.getOrElse(0))
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user