Skip to content

Instantly share code, notes, and snippets.

@andypetrella
Created February 27, 2012 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andypetrella/1927260 to your computer and use it in GitHub Desktop.
Save andypetrella/1927260 to your computer and use it in GitHub Desktop.
Create Views in Play 2.0 for Neo4J
#Get all users and add them to the graph
routeToAllUsers = playRoutes.controllers.Users.j_all().url
$.get(
routeToAllUsers
(us) ->
#do something with the retrieved users as Json
)
object Groups extends Controller {
// create a new Group based on its given name
def create = Action {
implicit request => {
//a form that will create a Group based on the request body. See how apply and unapply functions are given after the mapping definition
Form[Group](
mapping(
"name" -> nonEmptyText
)(
(name: String) => Group(null.asInstanceOf[Int], name)
)(
(group: Group) => Some(group.name)
)
).bindFromRequest().fold(
f => BadRequest("Missing parameter"),
(group: Group) => {
Ok(toJson(group.save))
}
)
}
}
}
object Users extends Controller {
//defined in route as: GET /users
def j_all = Action {
Ok(toJson(Model.all[User]))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment