Skip to content

Commit

Permalink
oops, forget to add the files!!
Browse files Browse the repository at this point in the history
  • Loading branch information
fommil committed Oct 25, 2012
1 parent d425a3b commit e371832
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
@@ -0,0 +1,34 @@
package org.cakesolutions.akkapatterns.api

import java.util.UUID
import spray.json._
import spray.httpx.marshalling._
import org.cakesolutions.akkapatterns.domain._
import org.cakesolutions.akkapatterns.core.application._

// might move upstream: https://github.com/spray/spray-json/issues/24
@deprecated("expecting to move upstream", "") trait UuidMarshalling {
implicit object UuidJsonFormat extends JsonFormat[UUID] {
def write(x: UUID) = JsString(x toString ())
def read(value: JsValue) = value match {
case JsString(x) => UUID.fromString(x)
case x => deserializationError("Expected UUID as JsString, but got " + x)
}
}
}

trait Marshalling extends DefaultJsonProtocol with UuidMarshalling {

implicit val UserFormat = jsonFormat3(User)
implicit val NotRegisteredUserFormat = jsonFormat1(NotRegisteredUser)
implicit val RegisteredUserFormat = jsonFormat1(RegisteredUser)

implicit val AddressFormat = jsonFormat3(Address)
implicit val CustomerFormat = jsonFormat5(Customer)
implicit val RegisterCustomerFormat = jsonFormat2(RegisterCustomer)
implicit val NotRegisteredCustomerFormat = jsonFormat1(NotRegisteredCustomer)
implicit val RegisteredCustomerFormat = jsonFormat2(RegisteredCustomer)

implicit val ImplementationFormat = jsonFormat3(Implementation)
implicit val SystemInfoFormat = jsonFormat2(SystemInfo)
}
29 changes: 29 additions & 0 deletions sbt/src/main/scala/org/cakesolutions/akkapatterns/api/user.scala
@@ -0,0 +1,29 @@
package org.cakesolutions.akkapatterns.api

import akka.actor.ActorSystem
import spray.routing.Directives
import akka.pattern.ask
import spray.httpx.marshalling.MetaMarshallers
import spray.httpx.SprayJsonSupport._
import org.cakesolutions.akkapatterns.domain.User
import org.cakesolutions.akkapatterns.core.application.{ NotRegisteredUser, RegisteredUser }

/**
* @author janmachacek
*/
class UserService(implicit val actorSystem: ActorSystem) extends Directives with DefaultTimeout with Marshalling with MetaMarshallers {
def userActor = actorSystem.actorFor("/user/application/user")

val route =
path("user" / "register") {
post {
entity(as[User]) { user =>
complete {
import scala.concurrent.ExecutionContext.Implicits._
(userActor ? RegisteredUser(user)).mapTo[Either[NotRegisteredUser, RegisteredUser]]
}
}
}
}

}

0 comments on commit e371832

Please sign in to comment.