Skip to content

Instantly share code, notes, and snippets.

@arturaz
Created September 10, 2012 14:52
Show Gist options
  • Save arturaz/3691294 to your computer and use it in GitHub Desktop.
Save arturaz/3691294 to your computer and use it in GitHub Desktop.
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