Skip to content

Instantly share code, notes, and snippets.

@nelsonblaha
Last active August 29, 2015 14:07
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 nelsonblaha/bb121da3a8b680dcaa8c to your computer and use it in GitHub Desktop.
Save nelsonblaha/bb121da3a8b680dcaa8c to your computer and use it in GitHub Desktop.
Pattern for sorting ways to get a resource "UserFavorites"
def index = Action.async { implicit request =>
ChanneledPresenter(context) flatMap { presenter =>
// alternatives for resource fetching, which may or may not be available
val getAccountFavorites = ???
val createAccountFavorites = ???
val getSessionFavorites = ???
val createSessionFavorites = ???
Seq(getAccountFavorites,
createAccountFavorites,
getSessionFavorites,
createSessionFavorites).flatten.headOption match {
case Some(futureTryUserFavorites) =>
for {
Success(userFavorites) <- futureTryUserFavorites
} yield {
Ok(views.html.favorites.index(FavoritesPresenter(releases, photos, videos)))
}
case None => Ok(views.html.favorites.index(FavoritesPresenter(Seq.empty, Seq.empty, Seq.empty)))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment