Skip to content
Browse files

merge and updates

  • Loading branch information...
2 parents efcafe1 + d49763a commit 43290c776ebf017699c6fc6ecdfe64cd1334b9b8 @jamesward committed Apr 28, 2012
View
3 .gitignore
@@ -2,5 +2,8 @@
/project/project
/project/target
/target
+/tmp
+/out
/*.iml
/.idea
+/.idea_modules
View
19 README.md
@@ -0,0 +1,19 @@
+Deploy on Heroku
+----------------
+
+1. [Install the Heroku Toolbelt](http://toolbelt.heroku.com)
+
+2. [Signup for a Heroku Account](http://heroku.com/signup)
+
+3. Login to Heroku:
+
+ $ heroku login
+
+4. Create a new Heroku app:
+
+ $ heroku create -s cedar
+
+5. Push the local repo to Heroku:
+
+ $ git push heroku master
+
View
30 app/controllers/Application.java
@@ -1,30 +0,0 @@
-package controllers;
-
-
-import models.Bar;
-import org.codehaus.jackson.JsonNode;
-import play.data.Form;
-import play.mvc.Controller;
-import play.mvc.Result;
-import views.html.index;
-
-import static play.libs.Json.toJson;
-
-public class Application extends Controller {
-
- public static Result index() {
- return ok(index.render(form(Bar.class)));
- }
-
- public static Result addBar() {
- Form<Bar> form = form(Bar.class).bindFromRequest();
- Bar bar = form.get();
- bar.save();
- return redirect(controllers.routes.Application.index());
- }
-
- public static Result listBars() {
- JsonNode jsonNodes = toJson(Bar.find.all());
- return ok(jsonNodes);
- }
-}
View
35 app/controllers/Application.scala
@@ -0,0 +1,35 @@
+package controllers
+
+import play.api.data.Form
+import play.api.data.Forms.{single, nonEmptyText}
+import play.api.mvc.{Action, Controller}
+import anorm.NotAssigned
+import com.codahale.jerkson.Json
+
+import models.Bar
+
+
+object Application extends Controller {
+
+ val barForm = Form(
+ single("name" -> nonEmptyText)
+ )
+
+ def index = Action {
+ Ok(views.html.index(barForm))
+ }
+
+ def addBar() = Action { implicit request =>
+ barForm.bindFromRequest.value map { name =>
+ Bar.create(Bar(NotAssigned, name))
+ Redirect(routes.Application.index())
+ } getOrElse BadRequest
+ }
+
+ def listBars() = Action {
+ val bars = Bar.findAll()
+ val json = Json.generate(bars)
+ Ok(json).as(JSON)
+ }
+
+}
View
18 app/models/Bar.java
@@ -1,18 +0,0 @@
-package models;
-
-import play.db.ebean.Model;
-
-import javax.persistence.Entity;
-import javax.persistence.Id;
-
-@Entity
-public class Bar extends Model {
-
- @Id
- public String id;
-
- public String name;
-
- public static Model.Finder<String, Bar> find = new Model.Finder(String.class, Bar.class);
-
-}
View
34 app/models/Bar.scala
@@ -0,0 +1,34 @@
+package models
+
+import play.api.db._
+import play.api.Play.current
+
+import anorm._
+import anorm.SqlParser._
+
+case class Bar(id: Pk[Long], name: String)
+
+object Bar {
+
+ val simple = {
+ get[Pk[Long]]("id") ~
+ get[String]("name") map {
+ case id~name => Bar(id, name)
+ }
+ }
+
+ def findAll(): Seq[Bar] = {
+ DB.withConnection { implicit connection =>
+ SQL("select * from bar").as(Bar.simple *)
+ }
+ }
+
+ def create(bar: Bar): Unit = {
+ DB.withConnection { implicit connection =>
+ SQL("insert into bar(name) values ({name})").on(
+ 'name -> bar.name
+ ).executeUpdate()
+ }
+ }
+
+}
View
6 app/views/index.scala.html
@@ -1,8 +1,8 @@
-@(form: play.data.Form[Bar])
+@(form: play.api.data.Form[String])
@main("Welcome to Play 2.0") {
- <script src="@routes.Assets.at("javascripts/index.js")" type="text/javascript"></script>
+ <script src="@routes.Assets.at("javascripts/index.min.js")" type="text/javascript"></script>
<ul id="bars"></ul>
@@ -11,4 +11,4 @@
<input type="submit"/>
}
-}
+}
View
1 app/views/main.scala.html
@@ -5,6 +5,7 @@
<html>
<head>
<title>@title</title>
+ <link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
</head>
View
44 conf/application.conf
@@ -1,51 +1,47 @@
-# Configuration
-
-application.name=PlayBars2a
+# This is the main configuration file for the application.
+# ~~~~~
# Secret key
# ~~~~~
# The secret key is used to secure cryptographics functions.
# If you deploy your application to several instances be sure to use the same key!
-application.secret="E27D^[_<Lpt0vjad]de;3/i;tx3gpRmG4Byof/3nahO/dIo9gbsMWut1w3xg[>9W"
+application.secret="ohoNuVPmVIxMd9jH]Y5nd;c^aiG7<DSRubl@S;LLLWyHEyrE2a4n`Ixe1=fv8]Yu"
+
+# The application languages
+# ~~~~~
+application.langs="en"
+
+# Global object class
+# ~~~~~
+# Define the Global object class for this application.
+# Default to Global in the root package.
+# global=Global
# Database configuration
# ~~~~~
# You can declare as many datasources as you want.
# By convention, the default datasource is named `default`
-
+#
db.default.driver=org.h2.Driver
-#db.default.driver=org.postgresql.Driver
-
-
-#eventually moving to heroku, we need to use an environment variable
-#for an in-memory database set this to --- jdbc:h2:mem:play
-#for postgresql database set this to --- jdbc:postgresql://localhost:5432/postgres?user=postgres&password=oracle
-
db.default.url="jdbc:h2:mem:play"
+# db.default.user=sa
+# db.default.password=
-# Ebean configuration
-# ~~~~~
-# You can declare as many Ebean servers as you want.
-# By convention, the default server is named `default`
-ebean.default="models.*"
-
-# Assets configuration
+# Evolutions
# ~~~~~
-assets.cache./public/stylesheets/bootstrap.min.css="max-age=3600"
+# You can disable evolutions if needed
+# evolutionplugin=disabled
# Logger
# ~~~~~
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory .
# Root logger:
-logger=ERROR
+logger.root=ERROR
# Logger used by the framework:
logger.play=INFO
# Logger provided to your application:
logger.application=DEBUG
-
-
-
View
26 conf/evolutions/default/1.sql
@@ -1,26 +1,12 @@
-# --- Created by Ebean DDL
-# To stop Ebean DDL generation, remove this comment and start using Evolutions
+# --- First database schema
# --- !Ups
-create table bar (
- id varchar(255) not null,
- name varchar(255),
- constraint pk_bar primary key (id))
-;
-
-create sequence bar_seq;
-
-
-
+create table bar (
+ id SERIAL PRIMARY KEY,
+ name varchar(255) not null
+);
# --- !Downs
-SET REFERENTIAL_INTEGRITY FALSE;
-
-drop table if exists bar;
-
-SET REFERENTIAL_INTEGRITY TRUE;
-
-drop sequence if exists bar_seq;
-
+drop table if exists bar;
View
6 project/Build.scala
@@ -4,15 +4,15 @@ import PlayProject._
object ApplicationBuild extends Build {
- val appName = "play2bars-java"
+ val appName = "play2bars"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
"postgresql" % "postgresql" % "9.0-801.jdbc3"
)
- val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
- // Add your own project settings here
+ val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
+ // Add your own project settings here
)
}
View
0 public/stylesheets/main.css
No changes.

0 comments on commit 43290c7

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