mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Add endpoints for managing spaces to openapi spec
This commit is contained in:
@ -19,12 +19,5 @@ CREATE TABLE "space_member" (
|
||||
foreign key ("user_id") references "user_"("uid")
|
||||
);
|
||||
|
||||
CREATE TABLE "space_item" (
|
||||
"id" varchar(254) not null primary key,
|
||||
"space_id" varchar(254) not null,
|
||||
"item_id" varchar(254) not null,
|
||||
"created" timestamp not null,
|
||||
unique ("space_id", "item_id"),
|
||||
foreign key ("space_id") references "space"("id"),
|
||||
foreign key ("item_id") references "item"("itemid")
|
||||
);
|
||||
ALTER TABLE "item"
|
||||
ADD COLUMN "space_id" varchar(254) NULL;
|
||||
|
@ -27,7 +27,8 @@ case class RItem(
|
||||
dueDate: Option[Timestamp],
|
||||
created: Timestamp,
|
||||
updated: Timestamp,
|
||||
notes: Option[String]
|
||||
notes: Option[String],
|
||||
spaceId: Option[Ident]
|
||||
) {}
|
||||
|
||||
object RItem {
|
||||
@ -58,6 +59,7 @@ object RItem {
|
||||
None,
|
||||
now,
|
||||
now,
|
||||
None,
|
||||
None
|
||||
)
|
||||
|
||||
@ -80,6 +82,7 @@ object RItem {
|
||||
val created = Column("created")
|
||||
val updated = Column("updated")
|
||||
val notes = Column("notes")
|
||||
val space = Column("space_id")
|
||||
val all = List(
|
||||
id,
|
||||
cid,
|
||||
@ -96,7 +99,8 @@ object RItem {
|
||||
dueDate,
|
||||
created,
|
||||
updated,
|
||||
notes
|
||||
notes,
|
||||
space
|
||||
)
|
||||
}
|
||||
import Columns._
|
||||
@ -107,7 +111,7 @@ object RItem {
|
||||
all,
|
||||
fr"${v.id},${v.cid},${v.name},${v.itemDate},${v.source},${v.direction},${v.state}," ++
|
||||
fr"${v.corrOrg},${v.corrPerson},${v.concPerson},${v.concEquipment},${v.inReplyTo},${v.dueDate}," ++
|
||||
fr"${v.created},${v.updated},${v.notes}"
|
||||
fr"${v.created},${v.updated},${v.notes},${v.spaceId}"
|
||||
).update.run
|
||||
|
||||
def getCollective(itemId: Ident): ConnectionIO[Option[Ident]] =
|
||||
|
@ -1,5 +1,7 @@
|
||||
package docspell.store.records
|
||||
|
||||
import cats.effect._
|
||||
import cats.implicits._
|
||||
import docspell.common._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.impl.Implicits._
|
||||
@ -17,6 +19,12 @@ case class RSpace(
|
||||
|
||||
object RSpace {
|
||||
|
||||
def newSpace[F[_]: Sync](name: String, account: AccountId): F[RSpace] =
|
||||
for {
|
||||
nId <- Ident.randomId[F]
|
||||
now <- Timestamp.current[F]
|
||||
} yield RSpace(nId, name, account.collective, account.user, now)
|
||||
|
||||
val table = fr"space"
|
||||
|
||||
object Columns {
|
||||
@ -41,4 +49,35 @@ object RSpace {
|
||||
sql.update.run
|
||||
}
|
||||
|
||||
def update(v: RSpace): ConnectionIO[Int] =
|
||||
updateRow(
|
||||
table,
|
||||
and(id.is(v.id), collective.is(v.collectiveId), owner.is(v.owner)),
|
||||
name.setTo(v.name)
|
||||
).update.run
|
||||
|
||||
def existsByName(coll: Ident, spaceName: String): ConnectionIO[Boolean] =
|
||||
selectCount(id, table, and(collective.is(coll), name.is(spaceName)))
|
||||
.query[Int]
|
||||
.unique
|
||||
.map(_ > 0)
|
||||
|
||||
def findById(spaceId: Ident): ConnectionIO[Option[RSpace]] = {
|
||||
val sql = selectSimple(all, table, id.is(spaceId))
|
||||
sql.query[RSpace].option
|
||||
}
|
||||
|
||||
def findAll(
|
||||
coll: Ident,
|
||||
nameQ: Option[String],
|
||||
order: Columns.type => Column
|
||||
): ConnectionIO[Vector[RSpace]] = {
|
||||
val q = Seq(collective.is(coll)) ++ (nameQ match {
|
||||
case Some(str) => Seq(name.lowerLike(s"%${str.toLowerCase}%"))
|
||||
case None => Seq.empty
|
||||
})
|
||||
val sql = selectSimple(all, table, and(q)) ++ orderBy(order(Columns).f)
|
||||
sql.query[RSpace].to[Vector]
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
package docspell.store.records
|
||||
|
||||
import docspell.common._
|
||||
import docspell.store.impl.Column
|
||||
import docspell.store.impl.Implicits._
|
||||
|
||||
import doobie._
|
||||
import doobie.implicits._
|
||||
|
||||
case class RSpaceItem(
|
||||
id: Ident,
|
||||
spaceId: Ident,
|
||||
itemId: Ident,
|
||||
created: Timestamp
|
||||
)
|
||||
|
||||
object RSpaceItem {
|
||||
|
||||
val table = fr"space"
|
||||
|
||||
object Columns {
|
||||
|
||||
val id = Column("id")
|
||||
val space = Column("space_id")
|
||||
val item = Column("user_id")
|
||||
val created = Column("created")
|
||||
|
||||
val all = List(id, space, user, created)
|
||||
}
|
||||
|
||||
import Columns._
|
||||
|
||||
def insert(value: RSpaceItem): ConnectionIO[Int] = {
|
||||
val sql = insertRow(
|
||||
table,
|
||||
all,
|
||||
fr"${value.id},${value.spaceId},${value.itemId},${value.created}"
|
||||
)
|
||||
sql.update.run
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user