Skip to content
Browse files

Fixed play example using Play 2.2.1, bumped dependencies

  • Loading branch information...
1 parent dff2c59 commit 0dc0c2bb86521e3b35dfc0da55d68107f5d1c27c @seratch seratch committed Jan 9, 2014
View
6 README.md
@@ -31,8 +31,8 @@ Add `scalikejdbc-async` to your dependencies.
```scala
libraryDependencies ++= Seq(
"org.scalikejdbc" %% "scalikejdbc-async" % "[0.3,)",
- "com.github.mauricio" %% "postgresql-async" % "0.2.8",
- "com.github.mauricio" %% "mysql-async" % "0.2.8",
+ "com.github.mauricio" %% "postgresql-async" % "0.2.10",
+ "com.github.mauricio" %% "mysql-async" % "0.2.10",
"org.slf4j" % "slf4j-simple" % "[1.7,)" // slf4j implementation
)
```
@@ -43,7 +43,7 @@ If you're a Play2 user, use play-plugin too!
val appDependencies = Seq(
"org.scalikejdbc" %% "scalikejdbc-async" % "[0.3,)",
"org.scalikejdbc" %% "scalikejdbc-async-play-plugin" % "[0.3,)",
- "com.github.mauricio" %% "postgresql-async" % "0.2.8"
+ "com.github.mauricio" %% "postgresql-async" % "0.2.10"
)
```
View
41 play-sample/app/controllers/Companies.scala
@@ -6,6 +6,7 @@ import play.api.data._, Forms._, validation.Constraints._
import org.json4s._, ext.JodaTimeSerializers
import com.github.tototoshi.play2.json4s.native._
+import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import models._
@@ -14,17 +15,13 @@ object Companies extends Controller with Json4s {
implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
- def all = Action {
- Async {
- Company.findAll.map(companies => Ok(Extraction.decompose(companies)))
- }
+ def all = Action.async {
+ Company.findAll.map(companies => Ok(Extraction.decompose(companies)))
}
- def show(id: Long) = Action {
- Async {
- Company.find(id) map { companyOpt =>
- companyOpt map { company => Ok(Extraction.decompose(company)) } getOrElse NotFound
- }
+ def show(id: Long) = Action.async {
+ Company.find(id) map { companyOpt =>
+ companyOpt map { company => Ok(Extraction.decompose(company)) } getOrElse NotFound
}
}
@@ -37,27 +34,21 @@ object Companies extends Controller with Json4s {
)(CompanyForm.apply)(CompanyForm.unapply)
)
- def create = Action { implicit req =>
+ def create = Action.async { implicit req =>
companyForm.bindFromRequest.fold(
- formWithErrors => BadRequest("invalid parameters"),
- form => {
- Async {
- Company.create(name = form.name, url = form.url).map { company =>
- Created.withHeaders(LOCATION -> s"/companies/${company.id}")
- }
- }
+ formWithErrors => Future.successful(BadRequest("invalid parameters")),
+ form => Company.create(name = form.name, url = form.url).map { company =>
+ Created.withHeaders(LOCATION -> s"/companies/${company.id}")
}
)
}
- def delete(id: Long) = Action {
- Async {
- Company.find(id).map { companyOpt =>
- companyOpt map { company =>
- company.destroy()
- NoContent
- } getOrElse NotFound
- }
+ def delete(id: Long) = Action.async {
+ Company.find(id).map { companyOpt =>
+ companyOpt map { company =>
+ company.destroy()
+ NoContent
+ } getOrElse NotFound
}
}
View
114 play-sample/app/controllers/Programmers.scala
@@ -5,6 +5,8 @@ import play.api.data._, Forms._, validation.Constraints._
import org.json4s._, ext.JodaTimeSerializers
import com.github.tototoshi.play2.json4s.native._
+
+import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import models._
@@ -13,17 +15,13 @@ object Programmers extends Controller with Json4s {
implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
- def all = Action {
- Async {
- Programmer.findAll.map(programmers => Ok(Extraction.decompose(programmers)))
- }
+ def all = Action.async {
+ Programmer.findAll.map(programmers => Ok(Extraction.decompose(programmers)))
}
- def show(id: Long) = Action {
- Async {
- Programmer.find(id).map { programmerOpt =>
- programmerOpt map { programmer => Ok(Extraction.decompose(programmer)) } getOrElse NotFound
- }
+ def show(id: Long) = Action.async {
+ Programmer.find(id).map { programmerOpt =>
+ programmerOpt map { programmer => Ok(Extraction.decompose(programmer)) } getOrElse NotFound
}
}
@@ -36,82 +34,68 @@ object Programmers extends Controller with Json4s {
)(ProgrammerForm.apply)(ProgrammerForm.unapply)
)
- def create = Action { implicit req =>
+ def create = Action.async { implicit req =>
programmerForm.bindFromRequest.fold(
- formWithErrors => BadRequest("invalid parameters"),
- form => {
- Async {
- Programmer.create(name = form.name, companyId = form.companyId).map { programmer =>
- Created.withHeaders(LOCATION -> s"/programmers/${programmer.id}")
- }
- }
+ formWithErrors => Future.successful(BadRequest("invalid parameters")),
+ form => Programmer.create(name = form.name, companyId = form.companyId).map { programmer =>
+ Created.withHeaders(LOCATION -> s"/programmers/${programmer.id}")
}
)
}
- def addSkill(programmerId: Long, skillId: Long) = Action {
- Async {
- Programmer.find(programmerId).map { programmerOpt =>
- programmerOpt map { programmer =>
- try {
- Skill.find(skillId).map { skillOpt =>
- skillOpt map { skill => programmer.addSkill(skill) }
- }
- Ok
- } catch { case e: Exception => Conflict }
- } getOrElse NotFound
- }
- }
- }
-
- def deleteSkill(programmerId: Long, skillId: Long) = Action {
- Async {
- Programmer.find(programmerId).map { programmerOpt =>
- programmerOpt map { programmer =>
+ def addSkill(programmerId: Long, skillId: Long) = Action.async {
+ Programmer.find(programmerId).map { programmerOpt =>
+ programmerOpt map { programmer =>
+ try {
Skill.find(skillId).map { skillOpt =>
skillOpt map { skill => programmer.addSkill(skill) }
}
Ok
- } getOrElse NotFound
- }
+ } catch { case e: Exception => Conflict }
+ } getOrElse NotFound
}
}
- def joinCompany(programmerId: Long, companyId: Long) = Action {
- Async {
- for {
- companyOpt <- Company.find(companyId)
- programmerOpt <- Programmer.find(programmerId)
- } yield {
- companyOpt map { company =>
- programmerOpt.map { programmer =>
- programmer.copy(companyId = Some(company.id)).save()
- Ok
- } getOrElse BadRequest("Programmer not found!")
- } getOrElse BadRequest("Company not found!")
- }
+ def deleteSkill(programmerId: Long, skillId: Long) = Action.async {
+ Programmer.find(programmerId).map { programmerOpt =>
+ programmerOpt map { programmer =>
+ Skill.find(skillId).map { skillOpt =>
+ skillOpt map { skill => programmer.addSkill(skill) }
+ }
+ Ok
+ } getOrElse NotFound
}
}
- def leaveCompany(programmerId: Long) = Action {
- Async {
- Programmer.find(programmerId).map { programmerOpt =>
- programmerOpt map { programmer =>
- programmer.copy(companyId = None).save()
+ def joinCompany(programmerId: Long, companyId: Long) = Action.async {
+ for {
+ companyOpt <- Company.find(companyId)
+ programmerOpt <- Programmer.find(programmerId)
+ } yield {
+ companyOpt map { company =>
+ programmerOpt.map { programmer =>
+ programmer.copy(companyId = Some(company.id)).save()
Ok
} getOrElse BadRequest("Programmer not found!")
- }
+ } getOrElse BadRequest("Company not found!")
}
}
- def delete(id: Long) = Action {
- Async {
- Programmer.find(id).map { programmerOpt =>
- programmerOpt map { programmer =>
- programmer.destroy()
- NoContent
- } getOrElse NotFound
- }
+ def leaveCompany(programmerId: Long) = Action.async {
+ Programmer.find(programmerId).map { programmerOpt =>
+ programmerOpt map { programmer =>
+ programmer.copy(companyId = None).save()
+ Ok
+ } getOrElse BadRequest("Programmer not found!")
+ }
+ }
+
+ def delete(id: Long) = Action.async {
+ Programmer.find(id).map { programmerOpt =>
+ programmerOpt map { programmer =>
+ programmer.destroy()
+ NoContent
+ } getOrElse NotFound
}
}
View
46 play-sample/app/controllers/Skills.scala
@@ -5,6 +5,8 @@ import play.api.data._, Forms._, validation.Constraints._
import org.json4s._, ext.JodaTimeSerializers
import com.github.tototoshi.play2.json4s.native._
+
+import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import models._
@@ -13,19 +15,15 @@ object Skills extends Controller with Json4s {
implicit val formats = DefaultFormats ++ JodaTimeSerializers.all
- def all = Action {
- Async {
- Skill.findAll.map(skills => Ok(Extraction.decompose(skills)))
- }
+ def all = Action.async {
+ Skill.findAll.map(skills => Ok(Extraction.decompose(skills)))
}
- def show(id: Long) = Action {
- Async {
- Skill.find(id).map { skillOpt =>
- skillOpt map { skill =>
- Ok(Extraction.decompose(skill))
- } getOrElse NotFound
- }
+ def show(id: Long) = Action.async {
+ Skill.find(id).map { skillOpt =>
+ skillOpt map { skill =>
+ Ok(Extraction.decompose(skill))
+ } getOrElse NotFound
}
}
@@ -35,27 +33,21 @@ object Skills extends Controller with Json4s {
mapping("name" -> text.verifying(nonEmpty))(SkillForm.apply)(SkillForm.unapply)
)
- def create = Action { implicit req =>
+ def create = Action.async { implicit req =>
skillForm.bindFromRequest.fold(
- formWithErrors => BadRequest("invalid parameters"),
- form => {
- Async {
- Skill.create(name = form.name).map { skill =>
- Created.withHeaders(LOCATION -> s"/skills/${skill.id}")
- }
- }
+ formWithErrors => Future.successful(BadRequest("invalid parameters")),
+ form => Skill.create(name = form.name).map { skill =>
+ Created.withHeaders(LOCATION -> s"/skills/${skill.id}")
}
)
}
- def delete(id: Long) = Action {
- Async {
- Skill.find(id).map { skillOpt =>
- skillOpt map { skill =>
- skill.destroy()
- NoContent
- } getOrElse NotFound
- }
+ def delete(id: Long) = Action.async {
+ Skill.find(id).map { skillOpt =>
+ skillOpt map { skill =>
+ skill.destroy()
+ NoContent
+ } getOrElse NotFound
}
}
View
56 play-sample/conf/db/migration/default/V1__create_tables.sql
@@ -0,0 +1,56 @@
+drop table if exists programmer;
+create sequence programmer_id_seq start with 1;
+create table programmer (
+ id bigint not null default nextval('programmer_id_seq') primary key,
+ name varchar(255) not null,
+ company_id bigint,
+ created_timestamp timestamp not null,
+ deleted_timestamp timestamp
+);
+
+drop table if exists company;
+create sequence company_id_seq start with 1;
+create table company (
+ id bigint not null default nextval('company_id_seq') primary key,
+ name varchar(255) not null,
+ url varchar(255),
+ created_at timestamp not null,
+ deleted_at timestamp
+);
+
+drop table if exists skill;
+create sequence skill_id_seq start with 1;
+create table skill (
+ id bigint not null default nextval('skill_id_seq') primary key,
+ name varchar(255) not null,
+ created_at timestamp not null,
+ deleted_at timestamp
+);
+
+drop table if exists programmer_skill;
+create table programmer_skill (
+ programmer_id bigint not null,
+ skill_id bigint not null,
+ primary key(programmer_id, skill_id)
+);
+
+insert into company (name, url, created_at) values ('Typesafe', 'http://typesafe.com/', current_timestamp);
+insert into company (name, url, created_at) values ('Oracle', 'http://www.oracle.com/', current_timestamp);
+insert into company (name, url, created_at) values ('Google', 'http://www.google.com/', current_timestamp);
+insert into company (name, url, created_at) values ('Microsoft', 'http://www.microsoft.com/', current_timestamp);
+
+insert into skill (name, created_at) values ('Scala', current_timestamp);
+insert into skill (name, created_at) values ('Java', current_timestamp);
+insert into skill (name, created_at) values ('Ruby', current_timestamp);
+insert into skill (name, created_at) values ('MySQL', current_timestamp);
+insert into skill (name, created_at) values ('PostgreSQL', current_timestamp);
+
+
+insert into programmer (name, company_id, created_timestamp) values ('Alice', 1, current_timestamp);
+insert into programmer (name, company_id, created_timestamp) values ('Bob', 2, current_timestamp);
+insert into programmer (name, company_id, created_timestamp) values ('Chris', 1, current_timestamp);
+
+insert into programmer_skill values (1, 1);
+insert into programmer_skill values (1, 2);
+insert into programmer_skill values (2, 2);
+
View
3 play-sample/conf/play.plugins
@@ -1,2 +1,3 @@
-888:scalikejdbc.async.PlayPlugin
+666:com.github.tototoshi.play2.flyway.Plugin
+777:scalikejdbc.async.PlayPlugin
View
9 project/Build.scala
@@ -27,7 +27,7 @@ object ScalikeJDBCAsyncProject extends Build {
"com.github.mauricio" %% "postgresql-async" % mauricioVersion % "provided",
"com.github.mauricio" %% "mysql-async" % mauricioVersion % "provided",
"org.postgresql" % "postgresql" % "9.2-1003-jdbc4" % "test",
- "mysql" % "mysql-connector-java" % "5.1.26" % "test",
+ "mysql" % "mysql-connector-java" % "5.1.28" % "test",
"org.scalatest" %% "scalatest" % "1.9.1" % "test",
"ch.qos.logback" % "logback-classic" % "1.0.13" % "test"
)
@@ -79,9 +79,10 @@ object ScalikeJDBCAsyncProject extends Build {
"org.scalikejdbc" %% "scalikejdbc-interpolation" % scalikejdbcVersion,
"com.github.mauricio" %% "postgresql-async" % mauricioVersion,
"com.github.mauricio" %% "mysql-async" % mauricioVersion,
- "org.postgresql" % "postgresql" % "9.2-1003-jdbc4",
- "mysql" % "mysql-connector-java" % "5.1.26",
- "org.json4s" %% "json4s-ext" % "3.2.4",
+ "org.postgresql" % "postgresql" % "9.2-1004-jdbc41",
+ "com.github.tototoshi" %% "play-flyway" % "1.0.0",
+ "mysql" % "mysql-connector-java" % "5.1.28",
+ "org.json4s" %% "json4s-ext" % "3.2.6",
"com.github.tototoshi" %% "play-json4s-native" % "0.1.0"
)
play.Project(appName, appVersion, appDependencies, path = file("play-sample")).settings(

0 comments on commit 0dc0c2b

Please sign in to comment.
Something went wrong with that request. Please try again.