Last active
August 29, 2015 14:07
-
-
Save nelsonblaha/bb121da3a8b680dcaa8c to your computer and use it in GitHub Desktop.
Pattern for sorting ways to get a resource "UserFavorites"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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