Connect multiple items to a mail

This commit is contained in:
Eike Kettner 2020-01-09 18:20:59 +01:00
parent 7a3289c41d
commit 2d69d39dd1
3 changed files with 64 additions and 7 deletions

View File

@ -18,13 +18,21 @@ CREATE TABLE "useremail" (
CREATE TABLE "sentmail" ( CREATE TABLE "sentmail" (
"id" varchar(254) not null primary key, "id" varchar(254) not null primary key,
"uid" varchar(254) not null, "uid" varchar(254) not null,
"item_id" varchar(254) not null,
"message_id" varchar(254) not null, "message_id" varchar(254) not null,
"sender" varchar(254) not null, "sender" varchar(254) not null,
"subject" varchar(254) not null, "subject" varchar(254) not null,
"recipients" varchar(254) not null, "recipients" varchar(254) not null,
"body" text not null, "body" text not null,
"created" timestamp not null, "created" timestamp not null,
foreign key("uid") references "user_"("uid"), foreign key("uid") references "user_"("uid")
foreign key("item_id") references "item"("itemid") );
CREATE TABLE "sentmailitem" (
"id" varchar(254) not null primary key,
"item_id" varchar(254) not null,
"sentmail_id" varchar(254) not null,
"created" timestamp not null,
unique ("item_id", "sentmail_id"),
foreign key("item_id") references "item"("itemid"),
foreign key("sentmail_id") references "sentmail"("id")
); );

View File

@ -11,7 +11,6 @@ import emil.MailAddress
case class RSentMail( case class RSentMail(
id: Ident, id: Ident,
uid: Ident, uid: Ident,
itemId: Ident,
messageId: String, messageId: String,
sender: MailAddress, sender: MailAddress,
subject: String, subject: String,
@ -27,7 +26,6 @@ object RSentMail {
object Columns { object Columns {
val id = Column("id") val id = Column("id")
val uid = Column("uid") val uid = Column("uid")
val itemId = Column("item_id")
val messageId = Column("message_id") val messageId = Column("message_id")
val sender = Column("sender") val sender = Column("sender")
val subject = Column("subject") val subject = Column("subject")
@ -38,7 +36,6 @@ object RSentMail {
val all = List( val all = List(
id, id,
uid, uid,
itemId,
messageId, messageId,
sender, sender,
subject, subject,
@ -54,7 +51,7 @@ object RSentMail {
insertRow( insertRow(
table, table,
all, all,
sql"${v.id},${v.uid},${v.itemId},${v.messageId},${v.sender},${v.subject},${v.recipients},${v.body},${v.created}" sql"${v.id},${v.uid},${v.messageId},${v.sender},${v.subject},${v.recipients},${v.body},${v.created}"
).update.run ).update.run
def findByUser(userId: Ident): Stream[ConnectionIO, RSentMail] = def findByUser(userId: Ident): Stream[ConnectionIO, RSentMail] =

View File

@ -0,0 +1,52 @@
package docspell.store.records
import cats.effect._
import cats.implicits._
import doobie._
import doobie.implicits._
import docspell.common._
import docspell.store.impl.Column
import docspell.store.impl.Implicits._
case class RSentMailItem(
id: Ident,
itemId: Ident,
sentMailId: Ident,
created: Timestamp
) {}
object RSentMailItem {
def create[F[_]: Sync](itemId: Ident, sentmailId: Ident, created: Option[Timestamp] = None): F[RSentMailItem] =
for {
id <- Ident.randomId[F]
now <- created.map(_.pure[F]).getOrElse(Timestamp.current[F])
} yield RSentMailItem(id, itemId, sentmailId, now)
val table = fr"sentmailitem"
object Columns {
val id = Column("id")
val itemId = Column("item_id")
val sentMailId = Column("sentmail_id")
val created = Column("created")
val all = List(
id,
itemId,
sentMailId,
created
)
}
import Columns._
def insert(v: RSentMailItem): ConnectionIO[Int] =
insertRow(
table,
all,
sql"${v.id},${v.itemId},${v.sentMailId},${v.created}"
).update.run
}