Last active
May 18, 2020 08:07
-
-
Save adamw/8d291057f52db93ee2d9e9a4a164c65f to your computer and use it in GitHub Desktop.
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
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
// should fail with Error if user not found | |
def authorize(authToken: AuthToken): Future[User] = ??? | |
def findPetForUser(user: User, id: UUID): Future[Option[Pet]] = ??? | |
def addPetToUser(user: User, pet: Pet): Future[Unit] = ??? | |
val getPetWithLogic = getPet.serverLogicRecoverErrors { | |
case (authToken, id) => | |
authorize(authToken).flatMap { user => | |
findPetForUser(user, id).flatMap { | |
case Some(pet) => Future.successful(pet) | |
case None => Future.failed(Error("Not found", StatusCode.NotFound)) | |
} | |
} | |
} | |
val addPetWithLogic = addPet.serverLogicRecoverErrors { | |
case (authToken, pet) => | |
authorize(authToken).flatMap { user => | |
addPetToUser(user, pet) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment