mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
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:
@ -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]] = {
|
||||
|
@ -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)
|
||||
|
||||
|
Reference in New Issue
Block a user