/shipping/read-front/src/main/scala/ecommerce/shipping/HttpService.scala
https://github.com/pawelkaczor/ddd-leaven-akka-v2 · Scala · 40 lines · 29 code · 11 blank · 0 comment · 0 complexity · 2b3e2feb661f37a7e081113af5e41d00 MD5 · raw file
- package ecommerce.shipping
- import akka.actor.{Actor, ActorLogging, Props}
- import akka.http.scaladsl.Http
- import akka.http.scaladsl.server.Directives
- import pl.newicom.dddd.streams.ImplicitMaterializer
- import akka.util.Timeout
- import com.typesafe.config.Config
- import ecommerce.shipping.app.ShipmentViewEndpoint
- import org.json4s.Formats
- import pl.newicom.dddd.serialization.JsonSerHints._
- import pl.newicom.dddd.view.sql.SqlViewStore
- import scala.concurrent.duration.FiniteDuration
- import slick.jdbc.PostgresProfile
- object HttpService {
- def props(interface: String, port: Int, askTimeout: FiniteDuration): Props =
- Props(new HttpService(interface, port)(askTimeout))
- }
- class HttpService(interface: String, port: Int)(implicit askTimeout: Timeout) extends Actor with ActorLogging
- with ShippingReadFrontConfiguration with ImplicitMaterializer with Directives {
- import context.dispatcher
- implicit val formats: Formats = fromConfig(config)
- implicit val profile = PostgresProfile
- Http(context.system).bindAndHandle(route, interface, port)
- log.info(s"Listening on $interface:$port")
- override def receive: Receive = Actor.emptyBehavior
- override def config: Config = context.system.settings.config
- lazy val endpoints: ShipmentViewEndpoint = new ShipmentViewEndpoint
- private def route = (provide(new SqlViewStore(config)) & pathPrefix("ecommerce" / "shipping"))(endpoints)
- }