Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.epam.user.service
- import javax.inject.{Inject, Singleton}
- import org.joda.time.DateTime
- import slick.dbio.DBIO
- import scala.collection.immutable.HashMap
- import scala.concurrent.Future
- case class CreateUser(email: String, password: String = "", fullName: String)
- case class User(id: Long,
- createdAt: DateTime,
- email: String,
- password: String,
- fullName: String,
- profile: Map[String, String])
- @Singleton
- class UserService @Inject()(repository: UserRepository, cryptoService: CryptoService){
- def newModel(cu: CreateUser): User = ???
- def getByEmail(email: String): Future[Option[User]] = db.run(repository.getByEmail(email))
- def create(user: CreateUser): Future[Either[ServiceError, Long]] = ???
- }
- @Singleton
- class UserRepository {
- def getByEmail(email: String): DBIO[Option[User]] = ???
- def create(user: User): DBIO[Long] = ???
- }
- sealed trait ServiceError {
- val message: String
- }
- case class EntityNotFound(private val identifier: String, private val entityName: String) extends ServiceError {
- override val message: String = s"Entity $entityName[$identifier] not found"
- }
- case class DuplicateEntity(private val identifier: String, private val entityName: String) extends ServiceError {
- override val message: String = s"Entity $entityName[$identifier] already exists"
- }
- case class InvalidParameters(message: String) extends ServiceError
- case class InvalidAction(message: String = "Couldn't perform action from this state") extends ServiceError
- case class EmailNotSend(message: String = "Couldn't send email") extends ServiceError
- case class ForbiddenAction(message: String = "Don't have enough permission to perform action from this state") extends ServiceError
Add Comment
Please, Sign In to add comment