Skip to content

Commit

Permalink
merge and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesward committed Apr 28, 2012
2 parents efcafe1 + d49763a commit 43290c7
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 98 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,5 +2,8 @@
/project/project
/project/target
/target
/tmp
/out
/*.iml
/.idea
/.idea_modules
19 changes: 19 additions & 0 deletions 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

30 changes: 0 additions & 30 deletions app/controllers/Application.java

This file was deleted.

35 changes: 35 additions & 0 deletions 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)
}

}
18 changes: 0 additions & 18 deletions app/models/Bar.java

This file was deleted.

34 changes: 34 additions & 0 deletions 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()
}
}

}
6 changes: 3 additions & 3 deletions 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>

Expand All @@ -11,4 +11,4 @@
<input type="submit"/>
}

}
}
1 change: 1 addition & 0 deletions app/views/main.scala.html
Expand Up @@ -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>
Expand Down
44 changes: 20 additions & 24 deletions 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




26 changes: 6 additions & 20 deletions 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;
6 changes: 3 additions & 3 deletions project/Build.scala
Expand Up @@ -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
)

}
Empty file added public/stylesheets/main.css
Empty file.

0 comments on commit 43290c7

Please sign in to comment.