Skip to content
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
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 Jun 14, 2016
c854c70
zomg it works displaying
jlikesplants Jun 14, 2016
9b092da
working on scripts
pottery123 Jun 14, 2016
6b17799
trying to get scripts for schema working
jlikesplants Jun 14, 2016
51364ca
finally found load_schema typo, started adding seed script
jlikesplants Jun 15, 2016
16a652d
added schema working on seeding data
pottery123 Jun 15, 2016
dcc01d6
got movies to seed!
jlikesplants Jun 15, 2016
6f4af58
renamed data vars in seed.js to differentiate between tables. seeding…
jlikesplants Jun 16, 2016
62634c9
created schema for empty rentals table, cleaned up some comments
jlikesplants Jun 16, 2016
194fc04
starting to work on models/wrappers
jlikesplants Jun 16, 2016
c5aac17
fixed requires and db issues
jlikesplants Jun 16, 2016
c8fab73
all movie data displaying
jlikesplants Jun 16, 2016
eadc378
working on bug in controller
pottery123 Jun 17, 2016
6c6c2e6
fixed rude braces.
jlikesplants Jun 17, 2016
704d04c
bug fixed
pottery123 Jun 17, 2016
19ebb23
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 17, 2016
77d40a8
changed model to use .sort instead of .all
jlikesplants Jun 17, 2016
05a3b25
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 17, 2016
1e61999
adding routes for customer/rental data
jlikesplants Jun 17, 2016
036c339
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 17, 2016
76bfe49
working on bug in routes
pottery123 Jun 17, 2016
01db7bb
found missing export, now displaying customers
jlikesplants Jun 17, 2016
87165c8
have movies and customers sorting correctly
jlikesplants Jun 20, 2016
0415280
fixing rental seeds
jlikesplants Jun 20, 2016
3907026
working on getting currently checked out movies
pottery123 Jun 20, 2016
c210745
fixing empty array but for currently checked out movies
pottery123 Jun 20, 2016
0193251
took out comments, finally have current retals path working
jlikesplants Jun 21, 2016
638350a
first three passing test
pottery123 Jun 21, 2016
3786ba8
passing test has the right values for the keys
pottery123 Jun 21, 2016
bb6e54d
Get a list of customers that have checked out a copy in the past
pottery123 Jun 21, 2016
08d30df
got history endpoint working, cleaning up comments, had to edit seeds.
jlikesplants Jun 21, 2016
5ed8e29
removed comments, unused routes, unused functions. all endpoints for …
jlikesplants Jun 22, 2016
2a4118e
creating rentals routes
jlikesplants Jun 22, 2016
12a807f
working on testing
pottery123 Jun 22, 2016
7a468ad
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 22, 2016
c7231d2
rentals view function working
jlikesplants Jun 23, 2016
2eff470
I am going to change the format of the controller test
pottery123 Jun 23, 2016
ad77748
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 23, 2016
cabff11
working on test
pottery123 Jun 24, 2016
77ba333
trying to get rental checkout going
jlikesplants Jun 24, 2016
daf30f2
added routes, views for json and html doc pages)
jlikesplants Jun 24, 2016
67c8456
Merging test branch into additional endpoints branch
jlikesplants Jun 24, 2016
ef917e9
working on tests for customers models
pottery123 Jun 24, 2016
61545fa
Merging branch back into master
jlikesplants Jun 24, 2016
acdd339
dependency injection attempt halp
jlikesplants Jun 24, 2016
c611fe8
successfully saving new rental!
jlikesplants Jun 24, 2016
0c80a7f
fixing customers callback hopefully
jlikesplants Jun 24, 2016
5bc0bce
working on customers test
pottery123 Jun 24, 2016
f035248
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 24, 2016
834c6ba
checkout function is done! complete with fancy on-purpose status code.
jlikesplants Jun 24, 2016
04d8787
controller test for some reason are not working
pottery123 Jun 24, 2016
70277f6
Merge branch 'master' of github.com:justinewinnie/VideoStoreAPI
pottery123 Jun 24, 2016
9c28dad
trying to get return rental going
jlikesplants Jun 24, 2016
e540af7
Merging in tests and more rental endpoints.
jlikesplants Jun 24, 2016
3fbb676
doing some api stuff
jlikesplants Jun 24, 2016
f174495
api mostly done
jlikesplants Jun 24, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions app.js
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;
})
})
55 changes: 55 additions & 0 deletions controllers/customers_controller.js
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)
}
})
}
}

Copy link

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!

module.exports = CustomersController
55 changes: 55 additions & 0 deletions controllers/movies_controller.js
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)
}
})
},

Copy link

Choose a reason for hiding this comment

The 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
62 changes: 62 additions & 0 deletions controllers/rentals_controller.js
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
1 change: 1 addition & 0 deletions coverage/coverage.json

Large diffs are not rendered by default.

Loading