Fail early when source id is wrong

This commit is contained in:
Eike Kettner
2020-08-08 18:42:48 +02:00
parent 8b73331409
commit 43946ed347
2 changed files with 20 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package docspell.restserver.routes
import cats.data.OptionT
import cats.effect._
import cats.implicits._
@ -43,11 +44,21 @@ object UploadRoutes {
import dsl._
HttpRoutes.of {
case req @ POST -> Root / "item" / Ident(id) =>
submitFiles(backend, cfg, Left(id))(req, None, Priority.Low, dsl)
case req @ POST -> Root / "item" / Ident(srcId) =>
(for {
_ <- OptionT(backend.collective.findSource(srcId))
res <- OptionT.liftF(
submitFiles(backend, cfg, Left(srcId))(req, None, Priority.Low, dsl)
)
} yield res).getOrElseF(NotFound())
case req @ POST -> Root / "item" / Ident(itemId) / Ident(id) =>
submitFiles(backend, cfg, Left(id))(req, Some(itemId), Priority.Low, dsl)
case req @ POST -> Root / "item" / Ident(itemId) / Ident(srcId) =>
(for {
_ <- OptionT(backend.collective.findSource(srcId))
res <- OptionT.liftF(
submitFiles(backend, cfg, Left(srcId))(req, Some(itemId), Priority.Low, dsl)
)
} yield res).getOrElseF(NotFound())
}
}