Permalink
Browse files

upgrade to play 2.1

  • Loading branch information...
1 parent 7f2cea8 commit d6797edf1d7c44042e07537bfbbd08a7f2ce3d13 @jamesward committed Mar 5, 2013
Showing with 42 additions and 16 deletions.
  1. +9 −5 app/controllers/Application.scala
  2. +24 −3 app/models/Bar.scala
  3. +1 −1 app/views/main.scala.html
  4. +1 −0 conf/routes
  5. +5 −5 project/Build.scala
  6. +1 −1 project/build.properties
  7. +1 −1 project/plugins.sbt
@@ -1,11 +1,15 @@
package controllers
+import scala.collection.JavaConverters._
+
import play.api.data.Form
import play.api.data.Forms.{single, text}
import play.api.mvc.{Action, Controller}
-import com.codahale.jerkson.Json
+import play.api.libs.json.Json
+
+import models.{BarCompanion, Bar}
+import models.BarCompanion._
-import models.Bar
object Application extends Controller {
@@ -18,14 +22,14 @@ object Application extends Controller {
def addBar() = Action { implicit request =>
barForm.bindFromRequest.value map { name =>
- Bar.create(new Bar(null, name))
+ BarCompanion.create(new Bar(null, name))
Redirect(routes.Application.index())
} getOrElse BadRequest
}
def getBars() = Action {
- val bars = Bar.findAll()
- val json = Json.generate(bars)
+ val bars = BarCompanion.findAll().asScala
+ val json = Json.toJson(bars)
Ok(json).as("application/json")
}
View
@@ -1,10 +1,14 @@
package models
+import scala.reflect.BeanProperty
+
import play.api.Play.current
+import play.modules.mongodb.jackson.MongoDB
+import play.api.libs.json._
+
import net.vz.mongodb.jackson.{Id, ObjectId}
+
import org.codehaus.jackson.annotate.JsonProperty
-import play.modules.mongodb.jackson.MongoDB
-import reflect.BeanProperty
class Bar(@ObjectId @Id val id: String, @BeanProperty @JsonProperty("name") val name: String) {
@@ -13,7 +17,24 @@ class Bar(@ObjectId @Id val id: String, @BeanProperty @JsonProperty("name") val
def getId = id;
}
-object Bar {
+object BarCompanion {
+
+ implicit val barReads = new Reads[Bar] {
+ def reads(js: JsValue): JsResult[Bar] = JsSuccess(
+ new Bar(
+ (js \ "id").as[String],
+ (js \ "name").as[String]
+ )
+ )
+ }
+
+ implicit val barWrites = new Writes[Bar] {
+ def writes(bar: Bar): JsValue = {
+ Json.obj(
+ "name" -> bar.name
+ )
+ }
+ }
private lazy val db = MongoDB.collection("bars", classOf[Bar], classOf[String])
def create(bar: Bar) { db.save(bar) }
@@ -6,7 +6,7 @@
<head>
<title>@title</title>
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
- <script src="@routes.Assets.at("javascripts/jquery.min.js")" type="text/javascript"></script>
+ <script type='text/javascript' src='@routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))'></script>
</head>
<body>
@content
View
@@ -9,3 +9,4 @@ POST /bars controllers.Application.addBar
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)
+GET /webjars/*file controllers.WebJarAssets.at(file)
View
@@ -1,19 +1,19 @@
import sbt._
import Keys._
-import PlayProject._
+import play.Project._
object ApplicationBuild extends Build {
val appName = "play2bars-mongodb"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
- "com.jquery" % "jquery" % "1.7.1",
- "net.vz.mongodb.jackson" %% "play-mongo-jackson-mapper" % "1.0.0"
+ "org.webjars" % "webjars-play" % "2.1.0",
+ "org.webjars" % "jquery" % "1.9.1",
+ "net.vz.mongodb.jackson" %% "play-mongo-jackson-mapper" % "1.1.0"
)
- val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
- resolvers += "webjars" at "http://webjars.github.com/m2"
+ val main = play.Project(appName, appVersion, appDependencies).settings(
)
}
View
@@ -1 +1 @@
-sbt.version=0.11.3
+sbt.version=0.12.2
View
@@ -5,4 +5,4 @@ logLevel := Level.Warn
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
-addSbtPlugin("play" % "sbt-plugin" % "2.0.3")
+addSbtPlugin("play" % "sbt-plugin" % "2.1.0")

0 comments on commit d6797ed

Please sign in to comment.