Skip to content

Instantly share code, notes, and snippets.

@jchapuis
Last active March 22, 2021 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jchapuis/8d12cb3b56578b2c42f378631b946d6b to your computer and use it in GitHub Desktop.
Save jchapuis/8d12cb3b56578b2c42f378631b946d6b to your computer and use it in GitHub Desktop.
def getBlocksForResource[F[_, _]: BifunctorMonadError: Bilogger]
(resourceID: ResourceID, timeFilter: TimeFilter)
(implicit resourceRepo: ResourceRepo[F], blockRepo: BlockRepo[F]): F[ResourceBlockError, List[Block]] =
(for {
resource <- resourceRepo.get(resourceID)
blocks <- blockRepo.blocksForResource(resource, timeFilter)
_ <- F.info(show"Successfully generated ${blocks.size} blocks for resource $resourceID in interval $timeFilter")
} yield blocks).onLeft {
case repositoryError: RepositoryError => F.error(repositoryError.message)
case blockError: BlockError => F.error(blockError.message)
case notFound: ResourceNotFound => F.info(notFound.message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment