From f7eed3354547aca14462734cf7e70b06def9aac9 Mon Sep 17 00:00:00 2001 From: eikek Date: Thu, 8 Jul 2021 21:17:48 +0200 Subject: [PATCH] Return a 404 if a source was not found when checking a file --- .../src/main/scala/docspell/backend/ops/OItemSearch.scala | 6 +++--- .../scala/docspell/restserver/routes/CheckFileRoutes.scala | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala b/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala index 7ba0373e..3abc6771 100644 --- a/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala +++ b/modules/backend/src/main/scala/docspell/backend/ops/OItemSearch.scala @@ -55,7 +55,7 @@ trait OItemSearch[F[_]] { def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]] - def findByFileSource(checksum: String, sourceId: Ident): F[Vector[RItem]] + def findByFileSource(checksum: String, sourceId: Ident): F[Option[Vector[RItem]]] } @@ -280,11 +280,11 @@ object OItemSearch { def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]] = store.transact(QItem.findByChecksum(checksum, collective, Set.empty)) - def findByFileSource(checksum: String, sourceId: Ident): F[Vector[RItem]] = + def findByFileSource(checksum: String, sourceId: Ident): F[Option[Vector[RItem]]] = store.transact((for { coll <- OptionT(RSource.findCollective(sourceId)) items <- OptionT.liftF(QItem.findByChecksum(checksum, coll, Set.empty)) - } yield items).getOrElse(Vector.empty)) + } yield items).value) }) } diff --git a/modules/restserver/src/main/scala/docspell/restserver/routes/CheckFileRoutes.scala b/modules/restserver/src/main/scala/docspell/restserver/routes/CheckFileRoutes.scala index a3f44c26..31bf195d 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/routes/CheckFileRoutes.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/routes/CheckFileRoutes.scala @@ -43,7 +43,7 @@ object CheckFileRoutes { HttpRoutes.of { case GET -> Root / Ident(id) / checksum => for { items <- backend.itemSearch.findByFileSource(checksum, id) - resp <- Ok(convert(items)) + resp <- items.map(convert).map(Ok(_)).getOrElse(NotFound()) } yield resp } }