|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+package se.citerus.dddsample.infrastructure
|
|
|
2
|
+
|
|
|
3
|
+import java.time.ZonedDateTime
|
|
|
4
|
+
|
|
|
5
|
+import akka.actor.{Actor, ActorRef}
|
|
|
6
|
+import akka.pattern.ask
|
|
|
7
|
+import akka.util.Timeout
|
|
|
8
|
+import se.citerus.dddsample.domain.model.location.UnLocode
|
|
|
9
|
+import se.citerus.dddsample.infrastructure.BookingServiceActor.Book
|
|
|
10
|
+import spray.routing.HttpService
|
|
|
11
|
+
|
|
|
12
|
+import scala.concurrent.Future
|
|
|
13
|
+
|
|
|
14
|
+import scala.concurrent.duration._
|
|
|
15
|
+
|
|
|
16
|
+class CargoAdminActor(val bookingServiceActor: ActorRef) extends Actor with CargoAdminResource {
|
|
|
17
|
+
|
|
|
18
|
+ def actorRefFactory = context
|
|
|
19
|
+ def receive = runRoute(cargoAdminRoute)
|
|
|
20
|
+
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+trait CargoAdminResource extends HttpService { this: Actor =>
|
|
|
24
|
+
|
|
|
25
|
+ import spray.httpx.marshalling.BasicMarshallers._
|
|
|
26
|
+
|
|
|
27
|
+ import scala.concurrent.ExecutionContext.Implicits.global
|
|
|
28
|
+
|
|
|
29
|
+ implicit val timeout = Timeout(5.seconds)
|
|
|
30
|
+
|
|
|
31
|
+ val bookingServiceActor: ActorRef
|
|
|
32
|
+
|
|
|
33
|
+ val cargoAdminRoute =
|
|
|
34
|
+ path("admin" / "book") {
|
|
|
35
|
+ post {
|
|
|
36
|
+ parameters('origin, 'destination, 'arrivalTime) { (origin, destination, arrivalTime) =>
|
|
|
37
|
+ complete(book(origin, destination, arrivalTime).map(_.toString))
|
|
|
38
|
+ }
|
|
|
39
|
+ }
|
|
|
40
|
+ }
|
|
|
41
|
+
|
|
|
42
|
+ def book(origin: String, destination: String, arrivalTime: String): Future[Any] =
|
|
|
43
|
+ bookingServiceActor ? Book(new UnLocode(origin), new UnLocode(destination), ZonedDateTime.parse(arrivalTime))
|
|
|
44
|
+
|
|
|
45
|
+}
|