forked from AdaGold/video-store-api
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Preliminary PR #5
Open
jlikesplants
wants to merge
56
commits into
Ada-C5:master
Choose a base branch
from
jlikesplants:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
965781e
pseudo code of routes
jlikesplants c854c70
zomg it works displaying
jlikesplants 9b092da
working on scripts
pottery123 6b17799
trying to get scripts for schema working
jlikesplants 51364ca
finally found load_schema typo, started adding seed script
jlikesplants 16a652d
added schema working on seeding data
pottery123 dcc01d6
got movies to seed!
jlikesplants 6f4af58
renamed data vars in seed.js to differentiate between tables. seeding…
jlikesplants 62634c9
created schema for empty rentals table, cleaned up some comments
jlikesplants 194fc04
starting to work on models/wrappers
jlikesplants c5aac17
fixed requires and db issues
jlikesplants c8fab73
all movie data displaying
jlikesplants eadc378
working on bug in controller
pottery123 6c6c2e6
fixed rude braces.
jlikesplants 704d04c
bug fixed
pottery123 19ebb23
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 77d40a8
changed model to use .sort instead of .all
jlikesplants 05a3b25
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 1e61999
adding routes for customer/rental data
jlikesplants 036c339
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 76bfe49
working on bug in routes
pottery123 01db7bb
found missing export, now displaying customers
jlikesplants 87165c8
have movies and customers sorting correctly
jlikesplants 0415280
fixing rental seeds
jlikesplants 3907026
working on getting currently checked out movies
pottery123 c210745
fixing empty array but for currently checked out movies
pottery123 0193251
took out comments, finally have current retals path working
jlikesplants 638350a
first three passing test
pottery123 3786ba8
passing test has the right values for the keys
pottery123 bb6e54d
Get a list of customers that have checked out a copy in the past
pottery123 08d30df
got history endpoint working, cleaning up comments, had to edit seeds.
jlikesplants 5ed8e29
removed comments, unused routes, unused functions. all endpoints for …
jlikesplants 2a4118e
creating rentals routes
jlikesplants 12a807f
working on testing
pottery123 7a468ad
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 c7231d2
rentals view function working
jlikesplants 2eff470
I am going to change the format of the controller test
pottery123 ad77748
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 cabff11
working on test
pottery123 77ba333
trying to get rental checkout going
jlikesplants daf30f2
added routes, views for json and html doc pages)
jlikesplants 67c8456
Merging test branch into additional endpoints branch
jlikesplants ef917e9
working on tests for customers models
pottery123 61545fa
Merging branch back into master
jlikesplants acdd339
dependency injection attempt halp
jlikesplants c611fe8
successfully saving new rental!
jlikesplants 0c80a7f
fixing customers callback hopefully
jlikesplants 5bc0bce
working on customers test
pottery123 f035248
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 834c6ba
checkout function is done! complete with fancy on-purpose status code.
jlikesplants 04d8787
controller test for some reason are not working
pottery123 70277f6
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 9c28dad
trying to get return rental going
jlikesplants e540af7
Merging in tests and more rental endpoints.
jlikesplants 3fbb676
doing some api stuff
jlikesplants f174495
api mostly done
jlikesplants File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,68 @@ | ||
var express = require('express'); | ||
var path = require('path'); | ||
var favicon = require('serve-favicon'); | ||
var logger = require('morgan'); | ||
var cookieParser = require('cookie-parser'); | ||
var bodyParser = require('body-parser'); | ||
var express = require('express') | ||
var path = require('path') | ||
var favicon = require('serve-favicon') | ||
var logger = require('morgan') | ||
var cookieParser = require('cookie-parser') | ||
var bodyParser = require('body-parser') | ||
|
||
var routes = require('./routes/index'); | ||
var massive = require('massive') | ||
var connectionString = "postgres://localhost/video-store-api" | ||
|
||
var app = express(); | ||
var app = module.exports = 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('views', path.join(__dirname, 'views')) | ||
app.set('view engine', 'jade') | ||
|
||
//views...? | ||
app.engine('html', require('ejs').renderFile) | ||
app.set('view engine', 'html') | ||
|
||
var routes = require('./routes/index') | ||
|
||
var zomgRoutes = require('./routes/zomg') | ||
|
||
// uncomment after placing your favicon in /public | ||
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); | ||
app.use(logger('dev')); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use(cookieParser()); | ||
app.use(express.static(path.join(__dirname, 'public'))); | ||
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))) | ||
app.use(logger('dev')) | ||
app.use(bodyParser.json()) | ||
app.use(bodyParser.urlencoded({ extended: false })) | ||
app.use(cookieParser()) | ||
app.use(express.static(path.join(__dirname, 'public'))) | ||
|
||
app.use('/', routes); | ||
app.use('/', routes) | ||
app.use('/zomg', zomgRoutes) | ||
|
||
// catch 404 and forward to error handler | ||
app.use(function(req, res, next) { | ||
var err = new Error('Not Found'); | ||
err.status = 404; | ||
next(err); | ||
}); | ||
var err = new Error('Not Found') | ||
err.status = 404 | ||
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.status(err.status || 500) | ||
res.render('error', { | ||
message: err.message, | ||
error: err | ||
}); | ||
}); | ||
}) | ||
}) | ||
} | ||
|
||
// production error handler | ||
// no stacktraces leaked to user | ||
app.use(function(err, req, res, next) { | ||
res.status(err.status || 500); | ||
res.status(err.status || 500) | ||
res.render('error', { | ||
message: err.message, | ||
error: {} | ||
}); | ||
}); | ||
|
||
|
||
module.exports = app; | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var Customer = require("../models/customer") | ||
var Rental = require("../models/rental") | ||
|
||
var CustomersController = { | ||
|
||
index: function(req, res, next) { | ||
Customer.all(function(error, customers) { | ||
if(error) { | ||
var err = new Error("Error retrieving customers:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(customers) | ||
} | ||
}) | ||
}, | ||
|
||
sort: function(req, res, next) { | ||
Customer.sort(req.params.column_name, req.params.columns, req.query.n, req.query.p, function(error, customers) { | ||
if(error) { | ||
var err = new Error("Error retrieving customers:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(customers) | ||
} | ||
}) | ||
}, | ||
|
||
current: function(req, res, next) { | ||
Rental.current_id(req.params.id, req.params.column_name, function(error, rentals) { | ||
if(error) { | ||
var err = new Error("Error retrieving rentals" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(rentals) | ||
} | ||
}) | ||
}, | ||
|
||
history: function(req, res, next) { | ||
Rental.history_cust_id(req.params.id, req.params.column_name, req.params.column, function(error, rentals) { | ||
if(error) { | ||
var err = new Error("Error retrieving rentals:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(rentals) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
module.exports = CustomersController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var Movie = require("../models/movie") | ||
var Rental = require("../models/rental") | ||
|
||
var MoviesController = { | ||
|
||
index: function(req, res, next) { | ||
Movie.all(function(error, movies) { | ||
if(error) { | ||
var err = new Error("Error retrieving movies:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(movies) | ||
} | ||
}) | ||
}, | ||
|
||
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 am a little fuzzy on my javascript but I think you want to make sure to have semicolons at the end of each line. Looks like this is something to lookout for across your app. |
||
sort: function(req, res, next) { | ||
Movie.sort(req.params.column_name, req.query.n, req.query.p, function(error, movies) { | ||
if(error) { | ||
var err = new Error("Error retrieving movies:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(movies) | ||
} | ||
}) | ||
}, | ||
|
||
current: function(req, res, next) { | ||
Rental.current_title(req.params.title, req.params.columns, function(error, rentals) { | ||
if(error) { | ||
var err = new Error("Error retrieving rentals:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(rentals) | ||
} | ||
}) | ||
}, | ||
|
||
history: function(req, res, next) { | ||
Rental.history_title(req.params.title, req.params.column_name, function(error, rentals) { | ||
if(error) { | ||
var err = new Error("Error retrieving rentals:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(rentals) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
module.exports = MoviesController |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var Rental = require("../models/rental") | ||
var Movie = require("../models/movie") | ||
var Customer = require("../models/customer") | ||
|
||
var RentalsController = { | ||
view: function(req, res, next) { | ||
Rental.view(req.params.title, function(error, movies) { | ||
if(error) { | ||
var err = new Error("Error retrieving movies:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(movies) | ||
} | ||
}) | ||
}, | ||
|
||
customers: function(req, res, next) { | ||
Rental.customers(req.params.title, function(error, customers) { | ||
if(error) { | ||
var err = new Error("Error retrieving customers:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(customers) | ||
} | ||
}) | ||
}, | ||
|
||
check_out: function(req, res) { | ||
var title = req.params.title | ||
var customer_id = req.params.customer_id | ||
|
||
Rental.check_out(title, customer_id, function(error, result, next) { | ||
if(error) { | ||
var err = new Error("Error completing rental:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(result) | ||
res.statusCode = 204 | ||
} | ||
}) | ||
}, | ||
|
||
return_rental: function(req, res) { | ||
console.log("request: " + res) | ||
|
||
Rental.return_rental(title, customer_id, function(error, result, next) { | ||
if(error) { | ||
var err = new Error("Error completing rental:\n" + error.message) | ||
err.status = 500 | ||
next(err) | ||
} else { | ||
res.json(result) | ||
res.statusCode = 204 | ||
} | ||
}) | ||
} | ||
} | ||
|
||
module.exports = RentalsController |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Really nice job with error handling!