Created
February 27, 2012 21:36
-
-
Save andypetrella/1927260 to your computer and use it in GitHub Desktop.
Create Views in Play 2.0 for Neo4J
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
#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 | |
) |
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
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)) | |
} | |
) | |
} | |
} | |
} |
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
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