Last active
February 11, 2019 19:02
-
-
Save joshuakfarrar/ae2b4e46c72314f703124ac4cd7309ef 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
// RegistrationFormValidator.validateForm(form) returns Either[ValidationError, ValidRegistration] | |
// the expected return type of our HttpService[F] creator is F[Response[F]], so here we use .bimap | |
// and friends to finagle our validated form into that type. | |
val service: HttpService[F] = { | |
HttpService[F] { | |
case req @ POST -> Root / "users" => | |
req.decode[RegistrationForm] { form => | |
RegistrationFormValidator.validateForm(form).bimap(error => registrationFailed(error), | |
user => insertRegistration(User(UUID.randomUUID, user.email, user.password.bcrypt)) | |
.map(registrationSucceeded).flatMap(identity)).merge | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment