-
Notifications
You must be signed in to change notification settings - Fork 13
Jillian & Jade's EXTREME VIDEO EXPRESS (it's the 90s) API!!!!!11!!!!1! kewl. #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
b10191e
7e69068
f80ff64
fe3633f
3f994c9
bbec298
448164b
a46f4b2
e0611b6
bb8ed63
df311ed
cf69655
9aa4d2b
e929b92
cc7ebf3
de5b757
944c7a9
38d4c13
e4ff73c
22e7117
fca5fdd
4117137
1dc233a
a1f4b7f
7e73318
22c9cc3
e704d83
59ed614
dd0eabe
dc60de7
3ff63c7
ef395bf
dacb023
2b4eeda
b259277
65ab567
e18f050
75164a2
ef2faa5
3c56b1f
a2faf4f
8ca4618
b87aea8
2970cb0
e41e909
8a017c0
f74c963
4da9636
37ab377
0241bc0
c80b182
c7c524c
4162e25
23a8b4d
ee69dd8
3ae103b
857b62b
f450b9b
fd2f0c5
61d640f
a155863
de7a513
7221273
85797a9
1a25dd2
34aa7a5
76fcb75
b5cb520
1fcd557
9fc2fc3
b715f0f
92a93db
070171c
d537234
72dfb1b
21fc575
33fe746
cf20434
45c0130
33e1b27
c5bc420
b08e506
f54b3b2
db2982b
6995b8f
d08365a
3ae0f78
83e3f06
345ad66
d451759
c0506d2
9b7606e
d55204e
9f7da07
d808692
dd5593c
4f0e70e
dfdf543
a373466
fae25cf
34d7557
ceba217
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
node_modules/ | ||
coverage/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,47 @@ var favicon = require('serve-favicon'); | |
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
var massive = require('massive'); | ||
|
||
var routes = require('./routes/index'); | ||
var app = module.exports = express(); | ||
|
||
var app = express(); | ||
// database setup | ||
var connectionString = "postgres://localhost/extreme_video_express"; | ||
var db = massive.connectSync({connectionString: connectionString}); | ||
app.set('db', db); | ||
|
||
// view engine setup | ||
app.set('views', path.join(__dirname, 'views')); | ||
app.set('view engine', 'jade'); | ||
app.set('view engine', 'ejs'); | ||
|
||
|
||
// uncomment after placing your favicon in /public | ||
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); | ||
|
||
app.use(logger('dev')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logging is also really important! |
||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
|
||
app.use('/', routes); | ||
// | ||
// routes | ||
// | ||
|
||
// var routes = require('./routes/index'); | ||
var customers = require('./routes/customers'); | ||
var videos = require('./routes/videos'); | ||
var rentals = require('./routes/rentals'); | ||
var index = require('./routes/index') | ||
// app.use('/', routes); | ||
app.use('/customers', customers); | ||
app.use('/videos', videos); | ||
app.use('/rentals', rentals); | ||
app.use('/', index) | ||
|
||
// | ||
// error handlers | ||
// | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
|
@@ -30,14 +53,13 @@ app.use(function(req, res, next) { | |
next(err); | ||
}); | ||
|
||
// error handlers | ||
|
||
// development error handler | ||
// will print stacktrace | ||
if (app.get('env') === 'development') { | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.render('error', { | ||
res.json('error', { | ||
message: err.message, | ||
error: err | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var Customers = require("../models/customers"); | ||
|
||
var CustomersController = { | ||
|
||
getCustomers: function (request, response, next) { | ||
Customers.all(function(error, customers) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 500; | ||
err.error = "Error retrieving customer list." | ||
response.json(err) | ||
} else { | ||
response.json(customers) | ||
} | ||
}); | ||
}, | ||
|
||
// customer id, sort column, offset (p and n) | ||
getCustomersSorted: function(request, response) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've noticed on this method you didn't include next as a param but you do so in a lot of the other controller methods. I would recommend being consistent on whether or not you include it. (Caveat: I am not super familiar with Express and there may be a totally legitimate reason you did this :) ) |
||
Customers.sort(request.params.column, request.query.p, request.query.n, function(error, customers) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 404; | ||
err.error = "Not found :(" | ||
response.json(err) | ||
} else { | ||
response.json(customers) | ||
} | ||
|
||
}) | ||
}, | ||
} | ||
|
||
module.exports = CustomersController; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
var IndexController = { | ||
// Baseline project requirement, left for completion purposes: | ||
// getZomg: function (request, response) { | ||
// var locals = {}; | ||
// locals.zomg = JSON.stringify('It Works!!!!!'); | ||
// response.render('index', locals); | ||
// }, | ||
|
||
getApiDocs: function (request, response) { | ||
var locals = {} | ||
locals.weneedthisiguess = JSON.stringify() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is |
||
response.render('index', locals) | ||
} | ||
} | ||
|
||
module.exports = IndexController; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
var Rentals = require("../models/rentals"); | ||
|
||
var RentalsController = { | ||
|
||
getCurrentRentals: function (request, response, next) { | ||
Rentals.find_current(request.params.customer_id, function(error, rentals) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 500; | ||
err.error = "Error retrieving customer's current rentals." | ||
response.json(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yay error handling! |
||
} else { | ||
response.json(rentals) | ||
} | ||
}); | ||
}, | ||
|
||
getRentalHistory: function (request, response, next) { | ||
Rentals.find_history(request.params.customer_id, function(error, rentals) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 500; | ||
err.error = "Error retrieving customer's rental history." | ||
response.json(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider factoring out the error handling logic, since there's a lot of repetition There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A neat way to handle what @hougland is suggesting is creating an error |
||
} else { | ||
response.json(rentals) | ||
} | ||
}); | ||
}, | ||
|
||
getVideoCurrent: function(request, response, next) { | ||
Rentals.video_current(request.params.title, function(error, rentals) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 500; | ||
err.error = "Error retrieving video rentals list." | ||
response.json(err) | ||
} else { | ||
response.json(rentals) | ||
} | ||
}); | ||
}, | ||
|
||
getVideoHistory: function(request, response, next) { | ||
Rentals.find_video_history(request.params.title, request.params.ordered_by, function(error, rentals) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 500; | ||
err.error = "Error retrieving video rentals list." | ||
response.json(err) | ||
} else { | ||
response.json(rentals) | ||
} | ||
}) | ||
}, | ||
|
||
postCheckout: function(request, response, next) { | ||
Rentals.checkout(request.params.title, request.params.customer_id, function(error, rentals) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 304; | ||
err.error = "That video is not available for checkout" | ||
response.json(err) | ||
} else { | ||
response.json(rentals) | ||
} | ||
}) | ||
}, | ||
|
||
postCheckin: function(request, response, next) { | ||
Rentals.checkin(request.params.title, request.params.customer_id, function(error, rentals) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 304; | ||
err.error = "That video is not available for return" | ||
response.json(err) | ||
} else { | ||
response.json(rentals) | ||
} | ||
}) | ||
}, | ||
|
||
getOverdue: function(request, response, next) { | ||
Rentals.overdue(function(error, overdue_videos) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 404; | ||
err.error = "Not Found :(" | ||
response.json(err) | ||
} else { | ||
response.json(overdue_videos) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these all look nice and clean, though keep an eye on indentation |
||
module.exports = RentalsController; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var Videos = require("../models/videos"); | ||
|
||
var VideosController = { | ||
|
||
getVideos: function (request, response, next) { | ||
Videos.all(function(error, videos) { | ||
if(error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job incorporating error handling into all your controller methods! |
||
var err = new Error | ||
err.status = 500; | ||
err.error = "Error retrieving video rentals list." | ||
response.json(err) | ||
} else { | ||
response.json(videos) | ||
} | ||
}); | ||
}, | ||
|
||
// video id, sort column, offset (p and n) | ||
getVideosSorted: function(request, response) { | ||
Videos.sort(request.params.column, request.query.p, request.query.n, function(error, videos) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 404; | ||
err.error = "Not found :(" | ||
response.json(err) | ||
} else { | ||
response.json(videos) | ||
} | ||
|
||
}) | ||
}, | ||
|
||
getVideo: function (request, response) { | ||
Videos.find(request.params.title, function(error, video) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you only expecting a single video for this method? If so, should it be a FindOne method? |
||
if(error) { | ||
var err = new Error | ||
err.status = 404; | ||
err.error = "Not found :(" | ||
response.json(err) | ||
} else { | ||
response.json(video) | ||
} | ||
}) | ||
}, | ||
|
||
getVideosByCustomer: function (request, response) { | ||
Videos.customer_current(request.params.title, function(error, customers) { | ||
if(error) { | ||
var err = new Error | ||
err.status = 404; | ||
err.error = "Not found :(" | ||
response.json(err) | ||
} else { | ||
response.json(customers) | ||
} | ||
}); | ||
} | ||
} | ||
|
||
module.exports = VideosController; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
[ | ||
{ | ||
"customer_id": "1", | ||
"video_id": "1", | ||
"checkout_date": "Tues, 5 May 2015 07:54:14 -0700", | ||
"due_date": "Wed, 6 May 2015 07:54:14 -0700", | ||
"checkin_date": "Thu, 7 May 2015 07:54:14 -0700", | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "2", | ||
"video_id": "3", | ||
"checkout_date": "Fri, 8 May 2015 07:54:14 -0700", | ||
"due_date": "Wed, 9 May 2015 07:54:14 -0700", | ||
"checkin_date": null, | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "3", | ||
"video_id": "1", | ||
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700", | ||
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700", | ||
"checkin_date": "Fri, 1 May 2015 07:54:14 -0700", | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "4", | ||
"video_id": "1", | ||
"checkout_date": "Sat, 2 May 2015 07:54:14 -0700", | ||
"due_date": "Sun, 3 May 2015 07:54:14 -0700", | ||
"checkin_date": "Mon, 4 May 2015 07:54:14 -0700", | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "5", | ||
"video_id": "2", | ||
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700", | ||
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700", | ||
"checkin_date": "Fri, 1 May 2015 07:54:14 -0700", | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "6", | ||
"video_id": "3", | ||
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700", | ||
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700", | ||
"checkin_date": "Fri, 1 May 2015 07:54:14 -0700", | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "7", | ||
"video_id": "6", | ||
"checkout_date": "Wed, 22 Apr 2015 07:54:14 -0700", | ||
"due_date": "Thu, 23 Apr 2015 07:54:14 -0700", | ||
"checkin_date": null, | ||
"charge": 1.50 | ||
}, | ||
{ | ||
"customer_id": "8", | ||
"video_id": "1", | ||
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700", | ||
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700", | ||
"checkin_date": null, | ||
"charge": 1.50 | ||
} | ||
|
||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so jealous. This project would've helped me so much in my capstone. It took me 2 days to figure out how to set up a database and then connect with it from within my (non rails) app. So yay! This concept is really important :)