mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-05 14:45:59 +00:00
Fix item route responses
Also avoid storing empty strings in a nullable field.
This commit is contained in:
parent
2ecfb679d9
commit
88efe13209
@ -32,7 +32,7 @@ object Ident {
|
|||||||
|
|
||||||
def fromString(s: String): Either[String, Ident] =
|
def fromString(s: String): Either[String, Ident] =
|
||||||
if (s.forall(chars.contains)) Right(new Ident(s))
|
if (s.forall(chars.contains)) Right(new Ident(s))
|
||||||
else Left(s"Invalid identifier: $s. Allowed chars: ${chars.mkString}")
|
else Left(s"Invalid identifier: '$s'. Allowed chars: ${chars.toList.sorted.mkString}")
|
||||||
|
|
||||||
def fromBytes(bytes: ByteVector): Ident =
|
def fromBytes(bytes: ByteVector): Ident =
|
||||||
unsafe(bytes.toBase58)
|
unsafe(bytes.toBase58)
|
||||||
|
@ -96,15 +96,15 @@ object ItemRoutes {
|
|||||||
case req @ POST -> Root / Ident(id) / "notes" =>
|
case req @ POST -> Root / Ident(id) / "notes" =>
|
||||||
for {
|
for {
|
||||||
text <- req.as[OptionalText]
|
text <- req.as[OptionalText]
|
||||||
res <- backend.item.setNotes(id, text.text, user.account.collective)
|
res <- backend.item.setNotes(id, text.text.notEmpty, user.account.collective)
|
||||||
resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated"))
|
resp <- Ok(Conversions.basicResult(res, "Notes updated"))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
case req @ POST -> Root / Ident(id) / "name" =>
|
case req @ POST -> Root / Ident(id) / "name" =>
|
||||||
for {
|
for {
|
||||||
text <- req.as[OptionalText]
|
text <- req.as[OptionalText]
|
||||||
res <- backend.item.setName(id, text.text.getOrElse(""), user.account.collective)
|
res <- backend.item.setName(id, text.text.notEmpty.getOrElse(""), user.account.collective)
|
||||||
resp <- Ok(Conversions.basicResult(res, "Concerned equipment updated"))
|
resp <- Ok(Conversions.basicResult(res, "Name updated"))
|
||||||
} yield resp
|
} yield resp
|
||||||
|
|
||||||
case req @ POST -> Root / Ident(id) / "duedate" =>
|
case req @ POST -> Root / Ident(id) / "duedate" =>
|
||||||
@ -138,4 +138,10 @@ object ItemRoutes {
|
|||||||
} yield resp
|
} yield resp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
final implicit class OptionString(opt: Option[String]) {
|
||||||
|
def notEmpty: Option[String] =
|
||||||
|
opt.map(_.trim).filter(_.nonEmpty)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user