~ fix Location header + Record.asJSON method
authorAlexandre Bertails <bertails@w3.org>
Tue, 23 Aug 2011 17:05:59 -0400
changeset 32 7d4682ad247b
parent 29 5a7b4f478677
child 33 dff4c2111c56
~ fix Location header + Record.asJSON method
src/main/scala/Main.scala
src/main/scala/Record.scala
--- a/src/main/scala/Main.scala	Tue Aug 23 16:43:08 2011 -0400
+++ b/src/main/scala/Main.scala	Tue Aug 23 17:05:59 2011 -0400
@@ -98,7 +98,7 @@
          RecordDAO.insert(record) match {
            case Some(id) => {
              val path = "%s://%s/user/%s/run/%s" format (req.underlying.getScheme, host, user, id.toString)
-             Created ~> ContentLocation(path) ~> ResponseString("object available at %s" format path)
+             Created ~> Location(path) ~> ResponseString("object available at %s" format path)
            }
            case None => {
              InternalServerError ~> ResponseString("couldn't create object")
@@ -108,7 +108,7 @@
        case req @ Path(Seg("user" :: user :: "run" :: id :: Nil)) => req match {
          case GET(_) => {
            RecordDAO.findOneByID(id) match {
-             case Some(record) => Ok ~> ContentType("application/json") ~> ResponseString(record.toString)
+             case Some(record) => Ok ~> ContentType("application/json") ~> ResponseString(record.asJSON)
              case None => NotFound
            }
          }
--- a/src/main/scala/Record.scala	Tue Aug 23 16:43:08 2011 -0400
+++ b/src/main/scala/Record.scala	Tue Aug 23 17:05:59 2011 -0400
@@ -34,7 +34,11 @@
 
 case class Record(@Key("_id") id: ObjectId = new ObjectId,
                   activity:String,
-                  events:List[Event])
+                  events:List[Event]) {
+
+  def asJSON:String = grater[Record].asDBObject(this).toString
+
+}
 
 case class Event(@Key("t") timestamp:Long,
                  @Key("c") coordinates:Option[(Double, Double, Option[Double])],