Skip to content

Commit

Permalink
basic movies
Browse files Browse the repository at this point in the history
  • Loading branch information
pairing committed Dec 17, 2010
1 parent 0102edd commit 1320e8d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
37 changes: 35 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* Module dependencies.
*/

var express = require('express');
var express = require('express'),
Movies = require("./lib/movies");

var app = module.exports = express.createServer();

Expand All @@ -27,15 +28,47 @@ app.configure('production', function(){
});

// Routes
//

var data = [];
for(var i=0;i<10;i++){
var m = new Movies.movie();
m.title = "Tron Part:"+i.toString();
m.votes.up = i;
data.push(m);
}

app.get('/', function(req, res){
res.render('index', {
locals: {
title: 'Express'
title: 'Welcome to 3D Bash',
data: data
}
});
});

app.post("/movies", function(req, res){
if (req.body.title) {
var m = new Movies.movie();
m.title = req.body.title
data.push(m);
res.send({status: 201, data:m});
}
});

app.post("/up", function(req, res){
if (req.body.title) {
var m = //lookup movie
m.up++;
res.render('index', {
locals: {
title: 'Welcome to 3D Bash',
data: data
}
});
}
});

// Only listen on $ node app.js

if (!module.parent) {
Expand Down
Empty file added jakefile.js
Empty file.
4 changes: 4 additions & 0 deletions lib/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports.movie = function(){
return { title:"", votes: { up:0, down:0 } };
};

4 changes: 3 additions & 1 deletion views/index.jade
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
h1= title
p Welcome to #{title}
p= title
- each movie in data
li #{movie.title} :)#{movie.votes.up} :(#{movie.votes.down}

0 comments on commit 1320e8d

Please sign in to comment.