Created
March 26, 2022 18:25
-
-
Save supermanue/c341d0d53092a1aad297743ca079eada to your computer and use it in GitHub Desktop.
UserService class
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
object UserService { | |
def getUser(id: Int): ZIO[UserPersistence, AppError, User] = RIO.accessM(_.get.get(id)) | |
def createUser(id: Int, name: String): ZIO[UserPersistence, AppError, User] = | |
for { | |
user <- ZIO.fromEither(User.build(id, name)) | |
stored <- RIO.accessM[UserPersistence](_.get.create(user)) | |
} yield stored | |
def deleteUser(id: Int): RIO[UserPersistence, Boolean] = RIO.accessM(_.get.delete(id)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment