-
-
Save anuragsrivastava06/d20920047d6859d70067cbd0bc6e992e to your computer and use it in GitHub Desktop.
This file contains 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
package com.knoldus.DAO.user | |
import com.google.inject.ImplementedBy | |
import com.knoldus.DAO.db.{DBComponent, PostgresDbComponent} | |
import com.knoldus.DAO.user.mappings.{User, UserMapping} | |
import scala.concurrent.Future | |
@ImplementedBy(classOf[UserPostgresComponent]) | |
trait UserComponent extends UserMapping { | |
this: DBComponent => | |
import driver.api._ | |
/** | |
* Inserts user into database | |
* | |
* @param user | |
* @return | |
*/ | |
def insert(user: User): Future[Int] = { | |
db.run(userInfo += user) | |
} | |
/** | |
* Fetches user detail using email | |
* | |
* @param email | |
* @return Future[Option[User]] | |
**/ | |
def getUserByEmail(email: String): Future[Option[User]] = { | |
db.run(userInfo.filter(user => user.email === email).result.headOption) | |
} | |
/** | |
* Fetches user record with the help of userId | |
* | |
* @param userId | |
* @return Option[User] | |
*/ | |
def getUserByUserId(userId: String): Future[Option[User]] = { | |
db.run(userInfo.filter(user => user.id === userId).result.headOption) | |
} | |
/** | |
* Fetches All user from DB | |
* | |
* @return | |
*/ | |
def getAllUsers: Future[List[User]] = { | |
db.run(userInfo.to[List].result) | |
} | |
/** | |
* Checks if user with user id exists | |
* | |
* @param userId | |
* @return | |
*/ | |
def isUserIdExists(userId: String): Future[Boolean] = { | |
val query = userInfo.filter(user => user.id === userId).exists | |
db.run(query.result) | |
} | |
} | |
class UserPostgresComponent extends UserComponent with PostgresDbComponent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment