Created
December 12, 2016 13:42
-
-
Save iref/63f787febc57a77bb23bca1efb9f56ce 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
final case class UserId(id: Long) extends AnyVal | |
final case class User(email: String, name: String, passwordDigest: String, createdAt: Instant, updatedAt: Instant) | |
final case class UserAndId(user: User, id: UserId) | |
sealed abstract class SignupError extends Product with Serializable | |
case object EmailAlreadyUsed | |
final case class Authenticated(email: String, token: Token) | |
final case class Token(get: UUID = UUID.randomUUID()) | |
object UserRepository { | |
def save(user: User): ConnectionIO[UserId] = ??? | |
def findByEmail(email: String): ConnectionIO[Option[UserAndId]] = ??? | |
} | |
object SignupService { | |
import UserRepository._ | |
def signup(signupForm: SignupForm): ConnectionIO[Either[SignupError, Authenticated]] = { | |
OptionT(findByEmail(signupForm.email)).map { _ => | |
Either.left(EmailAlreadyUsed) | |
}.getOrElseF { | |
val newUser = createUser(signupForm) | |
saveUser(newUser).map { _ => | |
Either.right(Authenticated(user.email, Token())) | |
} | |
} | |
} | |
def createUser(signupForm: SignupForm): User = ??? | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment