Delete items by introducing a deleted state

When deleting items via the http api, they are not deleted anymore but
a new status "Deleted" is set. The collective insights contains now a
count separately for deleted items.
This commit is contained in:
eikek
2021-08-14 14:18:03 +02:00
parent 48d13a35fc
commit cb777e30c0
10 changed files with 45 additions and 8 deletions

View File

@ -65,6 +65,7 @@ object QCollective {
case class InsightData(
incoming: Int,
outgoing: Int,
deleted: Int,
bytes: Long,
tags: List[TagCount]
)
@ -84,6 +85,11 @@ object QCollective {
ItemState.validStates
)
).build.query[Int].unique
val q2 = Select(
count(i.id).s,
from(i),
i.cid === coll && i.state === ItemState.Deleted
).build.query[Int].unique
val fileSize = sql"""
select sum(length) from (
@ -106,11 +112,12 @@ object QCollective {
) as t""".query[Option[Long]].unique
for {
n0 <- q0
n1 <- q1
n2 <- fileSize
n3 <- tagCloud(coll)
} yield InsightData(n0, n1, n2.getOrElse(0L), n3)
incoming <- q0
outgoing <- q1
size <- fileSize
tags <- tagCloud(coll)
deleted <- q2
} yield InsightData(incoming, outgoing, deleted, size.getOrElse(0L), tags)
}
def tagCloud(coll: Ident): ConnectionIO[List[TagCount]] = {

View File

@ -336,6 +336,20 @@ object RItem {
def deleteByIdAndCollective(itemId: Ident, coll: Ident): ConnectionIO[Int] =
DML.delete(T, T.id === itemId && T.cid === coll)
def setState(
itemIds: NonEmptyList[Ident],
coll: Ident,
state: ItemState
): ConnectionIO[Int] =
for {
t <- currentTime
n <- DML.update(
T,
T.id.in(itemIds) && T.cid === coll,
DML.set(T.state.setTo(state), T.updated.setTo(t))
)
} yield n
def existsById(itemId: Ident): ConnectionIO[Boolean] =
Select(count(T.id).s, from(T), T.id === itemId).build.query[Int].unique.map(_ > 0)