mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-22 02:18:26 +00:00
Change custom field values for a single item
This commit is contained in:
@ -7,6 +7,7 @@ import cats.implicits._
|
||||
import fs2.Stream
|
||||
|
||||
import docspell.backend.ops.OCollective.{InsightData, PassChangeResult}
|
||||
import docspell.backend.ops.OCustomFields.SetValueResult
|
||||
import docspell.backend.ops.OJob.JobCancelResult
|
||||
import docspell.backend.ops.OUpload.{UploadData, UploadMeta, UploadResult}
|
||||
import docspell.backend.ops._
|
||||
@ -589,6 +590,18 @@ trait Conversions {
|
||||
|
||||
// basic result
|
||||
|
||||
def basicResult(r: SetValueResult): BasicResult =
|
||||
r match {
|
||||
case SetValueResult.FieldNotFound =>
|
||||
BasicResult(false, "The given field is unknown")
|
||||
case SetValueResult.ItemNotFound =>
|
||||
BasicResult(false, "The given item is unknown")
|
||||
case SetValueResult.ValueInvalid(msg) =>
|
||||
BasicResult(false, s"The value is invalid: $msg")
|
||||
case SetValueResult.Success =>
|
||||
BasicResult(true, "Custom field value set successfully.")
|
||||
}
|
||||
|
||||
def basicResult(cr: JobCancelResult): BasicResult =
|
||||
cr match {
|
||||
case JobCancelResult.JobNotFound => BasicResult(false, "Job not found")
|
||||
|
@ -6,6 +6,7 @@ import cats.implicits._
|
||||
|
||||
import docspell.backend.BackendApp
|
||||
import docspell.backend.auth.AuthToken
|
||||
import docspell.backend.ops.OCustomFields.{RemoveValue, SetValue}
|
||||
import docspell.backend.ops.OFulltext
|
||||
import docspell.backend.ops.OItemSearch.Batch
|
||||
import docspell.common.syntax.all._
|
||||
@ -358,6 +359,24 @@ object ItemRoutes {
|
||||
resp <- Ok(Conversions.basicResult(res, "Re-process task submitted."))
|
||||
} yield resp
|
||||
|
||||
case req @ PUT -> Root / Ident(id) / "customfield" =>
|
||||
for {
|
||||
data <- req.as[CustomFieldValue]
|
||||
res <- backend.customFields.setValue(
|
||||
id,
|
||||
SetValue(data.field, data.value, user.account.collective)
|
||||
)
|
||||
resp <- Ok(Conversions.basicResult(res))
|
||||
} yield resp
|
||||
|
||||
case DELETE -> Root / Ident(id) / "customfield" / Ident(fieldId) =>
|
||||
for {
|
||||
res <- backend.customFields.deleteValue(
|
||||
RemoveValue(fieldId, id, user.account.collective)
|
||||
)
|
||||
resp <- Ok(Conversions.basicResult(res, "Custom field value removed."))
|
||||
} yield resp
|
||||
|
||||
case DELETE -> Root / Ident(id) =>
|
||||
for {
|
||||
n <- backend.item.deleteItem(id, user.account.collective)
|
||||
|
Reference in New Issue
Block a user