/src/main/scala/me/archdev/restapi/Boot.scala

https://github.com/ArchDev/akka-http-rest · Scala · 47 lines · 35 code · 12 blank · 0 comment · 0 complexity · 67e14cd85a064fbe54ec4b7873f22bbb MD5 · raw file

  1. package me.archdev.restapi
  2. import akka.actor.ActorSystem
  3. import akka.http.scaladsl.Http
  4. import akka.stream.ActorMaterializer
  5. import me.archdev.restapi.core.auth.{ AuthService, JdbcAuthDataStorage }
  6. import me.archdev.restapi.core.profiles.{ JdbcUserProfileStorage, UserProfileService }
  7. import me.archdev.restapi.http.HttpRoute
  8. import me.archdev.restapi.utils.Config
  9. import me.archdev.restapi.utils.db.{ DatabaseConnector, DatabaseMigrationManager }
  10. import scala.concurrent.ExecutionContext
  11. object Boot extends App {
  12. def startApplication() = {
  13. implicit val actorSystem = ActorSystem()
  14. implicit val executor: ExecutionContext = actorSystem.dispatcher
  15. implicit val materializer: ActorMaterializer = ActorMaterializer()
  16. val config = Config.load()
  17. new DatabaseMigrationManager(
  18. config.database.jdbcUrl,
  19. config.database.username,
  20. config.database.password
  21. ).migrateDatabaseSchema()
  22. val databaseConnector = new DatabaseConnector(
  23. config.database.jdbcUrl,
  24. config.database.username,
  25. config.database.password
  26. )
  27. val userProfileStorage = new JdbcUserProfileStorage(databaseConnector)
  28. val authDataStorage = new JdbcAuthDataStorage(databaseConnector)
  29. val usersService = new UserProfileService(userProfileStorage)
  30. val authService = new AuthService(authDataStorage, config.secretKey)
  31. val httpRoute = new HttpRoute(usersService, authService, config.secretKey)
  32. Http().bindAndHandle(httpRoute.route, config.http.host, config.http.port)
  33. }
  34. startApplication()
  35. }