Created
September 10, 2012 14:52
-
-
Save arturaz/3691294 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private[this] def badParams(msg: String) = BadRequest( | |
Json.toJson(Map("error" -> ("Be sure to have these params defined: "+msg))) | |
) | |
def create = Action(parse.json) { request => | |
(for ( | |
modeStr <- (request.body \ "mode").asOpt[String]; | |
mode <- Graph.ConnectionsMode.withNameOpt(modeStr); | |
time <- (request.body \ "travel_time").asOpt[Int]; | |
lat <- (request.body \ "origin" \ "lat").asOpt[Double]; | |
lng <- (request.body \ "origin" \ "lng").asOpt[Double]; | |
smooth <- (request.body \ "smooth").asOpt[Boolean] | |
) yield (time, lat, lng, mode, smooth)) match { | |
case None => | |
badParams( | |
"travel_time: Int, origin[lat]: Double, origin[lng]: Double, " + | |
"smooth: Boolean, mode: one of " + | |
Graph.ConnectionsMode.values.mkString("/") | |
) | |
case Some((time, lat, lng, mode, smooth)) => | |
val shape = TimeMap.createShape( | |
Node.DegreeCoords(lat, lng), time, mode, smooth | |
) | |
Ok(Json.toJson(shape)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment