/
HttpService.scala
39 lines (28 loc) · 1.09 KB
/
HttpService.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ecommerce.sales.app
import akka.actor.{Actor, ActorLogging, Props}
import akka.http.scaladsl.Http
import akka.util.Timeout
import ecommerce.sales.ReservationOfficeId
import org.json4s.Formats
import pl.newicom.dddd.serialization.JsonSerHints.fromConfig
import pl.newicom.dddd.writefront.HttpCommandHandler
import scala.concurrent.duration.FiniteDuration
object HttpService {
def props(interface: String, port: Int, askTimeout: FiniteDuration): Props =
Props(new HttpService(interface, port)(askTimeout))
}
class HttpService(interface: String, port: Int)(implicit val timeout: Timeout)
extends Actor with SalesFrontConfiguration with HttpCommandHandler with ActorLogging {
implicit val formats: Formats = fromConfig(config)
Http(context.system).bindAndHandle(route, interface, port)
log.info(s"Listening on $interface:$port")
override def receive = Actor.emptyBehavior
override def offices = Set(ReservationOfficeId)
private def route = /*logRequestResult("sales")*/ {
pathPrefix("ecommerce") {
path("sales") {
handle[ecommerce.sales.Command]
}
}
}
}