Creating a QueryStringBindable for a nested classes in Scala and Playframework -
i'm trying see if can create querystringbindable following. i've 2 case classes boundingboxfilter has 2 locations
case class location(lat: double, lon: double) { def isempty: boolean = { lat == 0.0 && lon == 0.0 } } case class boundingboxfilter(start: location, end: location) { def isempty: boolean = { start.isempty && end.isempty } } now want define route
/filterbylocation mycontroller.filter(b: boundingboxfilter)
well, want url like? want query string parameters called? let's want phone call them slat, slon, elat, elon.
something this?
object boundingboxbindable extends querystringbindable[boundingbox] { def bind(key: string, params: map[string, seq[string]]) = { { slat <- params.get("slat") slon <- params.get("slon") elat <- params.get("elat") elon <- params.get("elon") } yield { seek { right(boundingbox(location(slat.todouble, slon.todouble), location(elat.todouble, elon.todouble))) } grab { case e: exception => left(e.getmessage) } } } def unbind(key: string, v: boundingbox) = { s"slat=${v.start.lat}&slon=${v.start.lon}&elat=${v.end.lat}&elon=${v.end.lon}" } } there illustration on playframework api documentation
scala playframework-2.0 nested query-string
No comments:
Post a Comment