Guest User

Untitled

a guest
Apr 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. package com.epam.user.service
  2.  
  3. import javax.inject.{Inject, Singleton}
  4. import org.joda.time.DateTime
  5. import slick.dbio.DBIO
  6.  
  7. import scala.collection.immutable.HashMap
  8. import scala.concurrent.Future
  9.  
  10. case class CreateUser(email: String, password: String = "", fullName: String)
  11.  
  12. case class User(id: Long,
  13. createdAt: DateTime,
  14. email: String,
  15. password: String,
  16. fullName: String,
  17. profile: Map[String, String])
  18.  
  19. @Singleton
  20. class UserService @Inject()(repository: UserRepository, cryptoService: CryptoService){
  21.  
  22. def newModel(cu: CreateUser): User = ???
  23.  
  24. def getByEmail(email: String): Future[Option[User]] = db.run(repository.getByEmail(email))
  25.  
  26. def create(user: CreateUser): Future[Either[ServiceError, Long]] = ???
  27.  
  28. }
  29.  
  30. @Singleton
  31. class UserRepository {
  32.  
  33. def getByEmail(email: String): DBIO[Option[User]] = ???
  34.  
  35. def create(user: User): DBIO[Long] = ???
  36. }
  37.  
  38.  
  39. sealed trait ServiceError {
  40. val message: String
  41. }
  42.  
  43. case class EntityNotFound(private val identifier: String, private val entityName: String) extends ServiceError {
  44. override val message: String = s"Entity $entityName[$identifier] not found"
  45. }
  46. case class DuplicateEntity(private val identifier: String, private val entityName: String) extends ServiceError {
  47. override val message: String = s"Entity $entityName[$identifier] already exists"
  48. }
  49. case class InvalidParameters(message: String) extends ServiceError
  50.  
  51. case class InvalidAction(message: String = "Couldn't perform action from this state") extends ServiceError
  52.  
  53. case class EmailNotSend(message: String = "Couldn't send email") extends ServiceError
  54.  
  55. 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