mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-04 18:39:33 +00:00
Add routes to restore deleted items
This commit is contained in:
parent
eede20b014
commit
f999662905
@ -124,6 +124,8 @@ trait OItem[F[_]] {
|
||||
collective: Ident
|
||||
): F[AddResult]
|
||||
|
||||
def restore(items: NonEmptyList[Ident], collective: Ident): F[UpdateResult]
|
||||
|
||||
def setItemDate(
|
||||
item: NonEmptyList[Ident],
|
||||
date: Option[Timestamp],
|
||||
@ -582,6 +584,17 @@ object OItem {
|
||||
.attempt
|
||||
.map(AddResult.fromUpdate)
|
||||
|
||||
def restore(
|
||||
items: NonEmptyList[Ident],
|
||||
collective: Ident
|
||||
): F[UpdateResult] =
|
||||
UpdateResult.fromUpdate(
|
||||
store
|
||||
.transact(
|
||||
RItem.restoreStateForCollective(items, ItemState.Created, collective)
|
||||
)
|
||||
)
|
||||
|
||||
def setItemDate(
|
||||
items: NonEmptyList[Ident],
|
||||
date: Option[Timestamp],
|
||||
|
@ -34,6 +34,7 @@ object ItemState {
|
||||
def processing: ItemState = Processing
|
||||
def created: ItemState = Created
|
||||
def confirmed: ItemState = Confirmed
|
||||
def deleted: ItemState = Deleted
|
||||
|
||||
def fromString(str: String): Either[String, ItemState] =
|
||||
str.toLowerCase match {
|
||||
|
@ -1609,7 +1609,9 @@ paths:
|
||||
tags: [ Item ]
|
||||
summary: Delete an item.
|
||||
description: |
|
||||
Delete an item and all its data permanently.
|
||||
Delete an item and all its data. This is a "soft delete", the
|
||||
item is still in the database and can be undeleted. A periodic
|
||||
job will eventually remove this item from the database.
|
||||
security:
|
||||
- authTokenHeader: []
|
||||
parameters:
|
||||
@ -1621,6 +1623,26 @@ paths:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
/sec/item/{id}/restore:
|
||||
post:
|
||||
operationId: "sec-item-restore-by-id"
|
||||
tags: [ Item ]
|
||||
summary: Restore a deleted item.
|
||||
description: |
|
||||
A deleted item can be restored as long it is still in the
|
||||
database. This action sets the item state to `created`.
|
||||
security:
|
||||
- authTokenHeader: []
|
||||
parameters:
|
||||
- $ref: "#/components/parameters/id"
|
||||
responses:
|
||||
200:
|
||||
description: Ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/item/{id}/tags:
|
||||
put:
|
||||
operationId: "sec-item-get-tags"
|
||||
@ -2307,6 +2329,29 @@ paths:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/items/restoreAll:
|
||||
post:
|
||||
operationId: "sec-items-restore-all"
|
||||
tags:
|
||||
- Item (Multi Edit)
|
||||
summary: Restore multiple items.
|
||||
description: |
|
||||
Given a list of item ids, restores all of them.
|
||||
security:
|
||||
- authTokenHeader: []
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/IdList"
|
||||
responses:
|
||||
200:
|
||||
description: Ok
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/BasicResult"
|
||||
|
||||
/sec/items/tags:
|
||||
post:
|
||||
operationId: "sec-items-add-all-tags"
|
||||
|
@ -187,6 +187,14 @@ object ItemMultiRoutes extends MultiIdSupport {
|
||||
resp <- Ok(res)
|
||||
} yield resp
|
||||
|
||||
case req @ POST -> Root / "restoreAll" =>
|
||||
for {
|
||||
json <- req.as[IdList]
|
||||
items <- readIds[F](json.ids)
|
||||
res <- backend.item.restore(items, user.account.collective)
|
||||
resp <- Ok(Conversions.basicResult(res, "Item(s) deleted"))
|
||||
} yield resp
|
||||
|
||||
case req @ PUT -> Root / "customfield" =>
|
||||
for {
|
||||
json <- req.as[ItemsAndFieldValue]
|
||||
|
@ -150,6 +150,12 @@ object ItemRoutes {
|
||||
resp <- Ok(Conversions.basicResult(res, "Item back to created."))
|
||||
} yield resp
|
||||
|
||||
case POST -> Root / Ident(id) / "restore" =>
|
||||
for {
|
||||
res <- backend.item.restore(NonEmptyList.of(id), user.account.collective)
|
||||
resp <- Ok(Conversions.basicResult(res, "Item restored."))
|
||||
} yield resp
|
||||
|
||||
case req @ PUT -> Root / Ident(id) / "tags" =>
|
||||
for {
|
||||
tags <- req.as[StringList].map(_.items)
|
||||
|
@ -152,7 +152,21 @@ object RItem {
|
||||
t <- currentTime
|
||||
n <- DML.update(
|
||||
T,
|
||||
T.id.in(itemIds) && T.cid === coll,
|
||||
T.id.in(itemIds) && T.cid === coll && T.state.in(ItemState.validStates),
|
||||
DML.set(T.state.setTo(itemState), T.updated.setTo(t))
|
||||
)
|
||||
} yield n
|
||||
|
||||
def restoreStateForCollective(
|
||||
itemIds: NonEmptyList[Ident],
|
||||
itemState: ItemState,
|
||||
coll: Ident
|
||||
): ConnectionIO[Int] =
|
||||
for {
|
||||
t <- currentTime
|
||||
n <- DML.update(
|
||||
T,
|
||||
T.id.in(itemIds) && T.cid === coll && T.state === ItemState.deleted,
|
||||
DML.set(T.state.setTo(itemState), T.updated.setTo(t))
|
||||
)
|
||||
} yield n
|
||||
|
Loading…
x
Reference in New Issue
Block a user