I am new to Scala and even what I am trying to achieve is too simple with Java, i feel confused with Scala.
What I want is to get a User
and then fill his Permission
using another query and based to his Role
and his individual Permissions
.
Until know I have the following code:
/**
* Finds a user by its loginInfo.
*
* @param loginInfo The loginInfo of the user to find.
* @return The found user or None if no user for the given login info could be found.
*/
def find(loginInfo: LoginInfo): Future[Option[models.admin.User]] = {
val userQuery = for {
dbLoginInfo <- loginInfoQuery(loginInfo)
dbUserLoginInfo <- Userlogininfo.filter(_.logininfoid === dbLoginInfo.id)
dbUser <- User.filter(_.userid === dbUserLoginInfo.userid)
user <- dbUser match {
case u =>
val permissionQuery = for {
dbUserPermission <- Userpermission.filter(_.userid === u.userid)
dbPermission <- Permission.filter(_.id === dbUserPermission.permissionid)
} yield dbPermission
val rolePermissionQuery = for {
dbUserRole <- Userrole.filter(_.userid === u.userid)
dbRole <- Role.filter(_.id === dbUserRole.roleid)
dbRolePermission <- Rolepermission.filter(_.roleid === dbRole.id)
dbPermission <- Permission.filter(_.id === dbRolePermission.permissionid)
} yield dbPermission
val unionPermissionQuery = permissionQuery union rolePermissionQuery
db.run(unionPermissionQuery.result).map(_.map(_.name).toList).map { permission =>
models.admin.User(
UUID.fromString(u.userid.toString),
u.firstname.toString,
u.lastname.toString,
u.jobtitle.toString,
loginInfo,
u.email.toString,
false,
Some(permission),
false)
}
case None => None
}
} yield user
db.run(userQuery.result.headOption)
}
I got the following errors:
pattern type is incompatible with expected type;
[error] found : None.type
[error] required: UserDAOImpl.this.User
[error] case None => None
[error] ^
[error] play/modules/admin/app/models/daos/impl/UserDAOImpl.scala:36: value map is not a member of Object
[error] user <- dbUser match {
[error] ^
[error] play/modules/admin/app/models/daos/impl/UserDAOImpl.scala:34: type mismatch;
[error] found : UserDAOImpl.this.Userlogininfo => slick.lifted.Query[Nothing,Nothing,Seq]
[error] required: UserDAOImpl.this.Userlogininfo => slick.lifted.Query[Nothing,T,Seq]
[error] dbUserLoginInfo <- Userlogininfo.filter(_.logininfoid === dbLoginInfo.id)
[error] ^
[error] play/modules/admin/app/models/daos/impl/UserDAOImpl.scala:33: type mismatch;
[error] found : UserDAOImpl.this.Logininfo => slick.lifted.Query[Nothing,Nothing,Seq]
[error] required: UserDAOImpl.this.Logininfo => slick.lifted.Query[Nothing,T,Seq]
[error] dbLoginInfo <- loginInfoQuery(loginInfo)
[error] ^
[error] play/modules/admin/app/models/daos/impl/UserDAOImpl.scala:69: value headOption is not a member of UserDAOImpl.this.driver.DriverAction[Seq[Nothing],UserDAOImpl.this.driver.api.NoStream,slick.dbio.Effect.Read]
[error] db.run(userQuery.result.headOption)
[error] ^
[error] 5 errors found
case u =>
will match anything. If you want to modify Option if it'sSome
and leave itNone
otherways you can usemap
. I don't really know how to help with other things as I don't know slick but maybe try to annotate types you expect and let compiler tell you where you fail. – Exegetic