Merge pull request #931 from eikek/fix/source-check-file

Return a 404 if a source was not found when checking a file
This commit is contained in:
mergify[bot] 2021-07-11 14:53:18 +00:00 committed by GitHub
commit f8df1bf29a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -55,7 +55,7 @@ trait OItemSearch[F[_]] {
def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]] 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]] = def findByFileCollective(checksum: String, collective: Ident): F[Vector[RItem]] =
store.transact(QItem.findByChecksum(checksum, collective, Set.empty)) 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 { store.transact((for {
coll <- OptionT(RSource.findCollective(sourceId)) coll <- OptionT(RSource.findCollective(sourceId))
items <- OptionT.liftF(QItem.findByChecksum(checksum, coll, Set.empty)) items <- OptionT.liftF(QItem.findByChecksum(checksum, coll, Set.empty))
} yield items).getOrElse(Vector.empty)) } yield items).value)
}) })
} }

View File

@ -43,7 +43,7 @@ object CheckFileRoutes {
HttpRoutes.of { case GET -> Root / Ident(id) / checksum => HttpRoutes.of { case GET -> Root / Ident(id) / checksum =>
for { for {
items <- backend.itemSearch.findByFileSource(checksum, id) items <- backend.itemSearch.findByFileSource(checksum, id)
resp <- Ok(convert(items)) resp <- items.map(convert).map(Ok(_)).getOrElse(NotFound())
} yield resp } yield resp
} }
} }