Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
e24f9a6
Adds node_modules to .gitignore.
corinnepingul Sep 17, 2015
d01802f
Sets up node app.
corinnepingul Sep 17, 2015
7dee606
Adds schema file to set up our database tables.
corinnepingul Sep 17, 2015
76635cc
Seeds the db.
corinnepingul Sep 17, 2015
f036c8f
WIP - initial routes (zomg)
Brennaleker Sep 17, 2015
c7d87a1
movies/zomg is working
Brennaleker Sep 17, 2015
32bf680
WIP trying to return json data of all movies.
corinnepingul Sep 17, 2015
d9d9cc9
/movies returns all movies in json.
corinnepingul Sep 18, 2015
9d996a0
Removes unecessary variable.
corinnepingul Sep 18, 2015
5cf6f94
Adds cl shortcuts.
corinnepingul Sep 18, 2015
8878a80
refactored to use a dynamic dtabase function for all
Brennaleker Sep 18, 2015
ff63512
customrs.all is working and displaying in json on the page
Brennaleker Sep 18, 2015
d1489d8
rental seeds
Brennaleker Sep 18, 2015
3318e77
Adds default value to rentals overdue table.
corinnepingul Sep 18, 2015
c9797a1
WIP - writing sort_by registered at query for customers
Brennaleker Sep 18, 2015
bfc4c3c
WIP sort by date
Brennaleker Sep 18, 2015
2155105
Makes registered_at in customers table an integer and stores it in th…
corinnepingul Sep 18, 2015
2e1f363
Changes variables and adds semicolon.
corinnepingul Sep 18, 2015
daa67b0
Refactor: pulls out date formatting into its own function.
corinnepingul Sep 21, 2015
be34e35
Changes name of sort function
corinnepingul Sep 21, 2015
6ad1a4a
Adds route for customers sort by name
corinnepingul Sep 21, 2015
52784d7
Adds name sort function for customer.
corinnepingul Sep 21, 2015
416f7c7
Refactors: pulls out customers variable to give it a larger scope.
corinnepingul Sep 21, 2015
7ab2b83
Adds route for customers sort by postal code.
corinnepingul Sep 21, 2015
51e4df9
Adds postal_code_sort function
corinnepingul Sep 21, 2015
f7858b4
movie title sort and release_date sort functioning
Brennaleker Sep 21, 2015
a856e59
refactored movies controller, added sortInfo variable to handle repea…
Brennaleker Sep 21, 2015
1ca9b99
Refactor: pulls out sort info into separate function. This function n…
corinnepingul Sep 21, 2015
caeb81f
Refactor: Changes name of function to SortCustomers.
corinnepingul Sep 21, 2015
aecac72
renamed sortInfo to sortMovies to be more explicit
Brennaleker Sep 21, 2015
7046df6
fixing merge conflicts
Brennaleker Sep 21, 2015
27b874a
Search movie by title functionality.
corinnepingul Sep 21, 2015
a851f9d
changed rental table to include movie title instead of id and updated…
Brennaleker Sep 21, 2015
ac894c1
fixed db seed issues for rentals
Brennaleker Sep 21, 2015
7d846a5
Formats rental date seeds.
corinnepingul Sep 21, 2015
42ba313
WIP - current_Rentals
Brennaleker Sep 21, 2015
a8059cc
WIP - current_rentals
Brennaleker Sep 21, 2015
bdea364
WIP
corinnepingul Sep 21, 2015
ed0e04c
fixed merge conflicts
Brennaleker Sep 21, 2015
5addacd
current_rentals is now functioning
Brennaleker Sep 21, 2015
82b3a03
Finishes writing find current customers with the specific movie check…
corinnepingul Sep 21, 2015
371a7bd
past_rentals is functioning
Brennaleker Sep 21, 2015
0ac8200
Adds semicolon.
corinnepingul Sep 21, 2015
bc6960d
Adds new route for past_customers.
corinnepingul Sep 21, 2015
dde3223
Adds current_customers and past_customers to model methods.
corinnepingul Sep 21, 2015
074f35f
created initial rentals files (controller, model, routes)
Brennaleker Sep 21, 2015
7203214
Adds route for past customers sorted by id.
corinnepingul Sep 21, 2015
61da686
Adds some seed data for rentals for testing.
corinnepingul Sep 21, 2015
9b99d30
Adds past_customers_id_sort endpoint.
corinnepingul Sep 21, 2015
3e45a98
Adds route for past customers sorted by name.
corinnepingul Sep 21, 2015
51977ef
Adds endpoint for past_customers_sort_by_name
corinnepingul Sep 21, 2015
39be395
Adds some seed data.
corinnepingul Sep 21, 2015
c79192c
Adds sort by checkout date to movies.
corinnepingul Sep 21, 2015
d433ef5
overdue in rentals endpoints is functioning
Brennaleker Sep 21, 2015
d775216
merge conflicts
Brennaleker Sep 21, 2015
076f564
WIP - setting up for testing
Brennaleker Sep 22, 2015
c295d72
2 running tests but running into no rentals table error again
Brennaleker Sep 22, 2015
0d0e825
removes development file.
corinnepingul Sep 22, 2015
dc67964
Merge branch 'cp+bl/master' of github.com:Brennaleker/C3Projects--Vid…
corinnepingul Sep 22, 2015
a851f1e
added db to git ignore and created test db
Brennaleker Sep 22, 2015
fb35f59
typo
Brennaleker Sep 22, 2015
8e1251a
Adds db file to gitignore.
corinnepingul Sep 22, 2015
4aae289
Adds db to gitignore.
corinnepingul Sep 22, 2015
19a589b
Merge conflicts.
corinnepingul Sep 22, 2015
4b31ffd
fixed git ignore file
Brennaleker Sep 22, 2015
34f313f
Managing merge conflicts.
corinnepingul Sep 22, 2015
3eed1ab
Adds test for /rentals/overdue endpoint.
corinnepingul Sep 22, 2015
dfded01
WIP movie controller tests
Brennaleker Sep 22, 2015
0dd001f
Adds tests for /customers.
corinnepingul Sep 22, 2015
c9ba69d
working test for all, release_date_sort and title_sort
Brennaleker Sep 22, 2015
1692d2c
current customers test working
Brennaleker Sep 22, 2015
7274003
Adds tests for /customers/registered_at_sort/:number_of_responses/:of…
corinnepingul Sep 22, 2015
0014c9e
movies/:title/past_customers/customer_id_sort tests passing
Brennaleker Sep 22, 2015
47787d8
Adds tests for /customers/name_sort/:number_of_records/:offset
corinnepingul Sep 22, 2015
41ee018
/:title/past_customers/customer_name_sort
Brennaleker Sep 22, 2015
f922ae6
Adds tests for /customers/postal_code_sort/:records_per_page/:offset
corinnepingul Sep 22, 2015
bf59642
all movie api endpoint tests completed and passing hooray
Brennaleker Sep 22, 2015
f6c567e
Adds tests for /customers/:id/current_rentals
corinnepingul Sep 22, 2015
e0995dc
Adds tests for /customers/:id/past_rentals
corinnepingul Sep 22, 2015
259d667
refactor - changed all routes to paths
Brennaleker Sep 22, 2015
9affe2f
refactor- rentals controller tests use path variables
Brennaleker Sep 22, 2015
e073a18
removes db/test.db
corinnepingul Sep 22, 2015
8823d80
deleted db files
Brennaleker Sep 22, 2015
42e99b3
Merge branch 'movie-tests' into cp+bl/master
Brennaleker Sep 22, 2015
cc3d036
WIP - rental check_in endpoint
Brennaleker Sep 23, 2015
48c28d8
our check_in rental function is creating a rental record, updating cu…
Brennaleker Sep 23, 2015
b143412
Adds checkin functionality. Check_in updates the movie inventory, and…
corinnepingul Sep 23, 2015
59e60c6
Adds to check that overdueselects rentals that both do not have a che…
corinnepingul Sep 23, 2015
2a84154
WIP overdue.
corinnepingul Sep 23, 2015
98ccd64
Finishes overdue functionality.
corinnepingul Sep 23, 2015
bf69d76
rewrote rentals:all to all_rentals so that it would update overdue re…
Brennaleker Sep 24, 2015
44d36cc
added endpoints for rentals/:title and rentals/:title/current_customers
Brennaleker Sep 24, 2015
70d229b
fixed overdue path and test
Brennaleker Sep 24, 2015
1611766
Does some syntax changes.
corinnepingul Sep 24, 2015
8543159
added rental log tests
Brennaleker Sep 24, 2015
28d9303
fixed merge conflicts
Brennaleker Sep 24, 2015
4b6f412
added more rentals seeds
Brennaleker Sep 24, 2015
62d1337
rentals post test is functioning
Brennaleker Sep 24, 2015
7b65edd
working update tests for rentals
Brennaleker Sep 24, 2015
95aff6b
switched check-in back to post
Brennaleker Sep 25, 2015
35a87a0
Refactors database model.
corinnepingul Sep 25, 2015
21203db
managing merge conflicts.
corinnepingul Sep 25, 2015
623c6e6
Fixes formatDate function.
corinnepingul Sep 25, 2015
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.DS_Store
node_modules
npm-debug.log
db/
68 changes: 68 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +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');

// establish our routes based on route files
var routes = require('./routes/index');
var movies = require('./routes/movies');
var customers = require('./routes/customers');
var rentals = require('./routes/rentals');


var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// 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')));

// Establishes our routes
app.use('/', routes);
app.use('/customers', customers);
app.use('/movies', movies);
app.use('/rentals', rentals);


// catch 404 and forward to error handler
app.use(function(req, res, next) {
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.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.render('error', {
message: err.message,
error: {}
});
});


module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('C3Projects--VideoStoreAPI:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
52 changes: 52 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"use strict";

var Customer = require('../customers');
var customer = new Customer();

var sortCustomers = function(sort_type, params, res) {
var records_per_page = params.records_per_page;
var offset = params.offset;
var customers = customer.sort_by(sort_type, records_per_page, offset, function(customers) {
return res.status(200).json(customers);
});
};

exports.customersController = {

all: function all(req, res) {
var customers = customer.all(function(customers) {
return res.status(200).json(customers);
});
},

registered_at_sort: function registered_at_sort(req, res) {
var sort_type = "registered_at";
sortCustomers(sort_type, req.params, res);
},

name_sort: function name_sort(req, res) {
var sort_type = "name";
sortCustomers(sort_type, req.params, res);
},

postal_code_sort: function postal_code_sort(req, res) {
var sort_type = "postal_code";
sortCustomers(sort_type, req.params, res);
},

current_rentals: function current_rentals(req, res) {
var id = req.params.id;

customer.current_rentals(id, function(current_rentals) {
return res.status(200).json(current_rentals);
});
},

past_rentals: function past_rentals(req, res) {
var id = req.params.id;

customer.past_rentals(id, function(past_rentals) {
return res.status(200).json(past_rentals);
});
}
}
82 changes: 82 additions & 0 deletions controllers/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
"use strict";

var Movie = require('../movies');
var movie = new Movie();

var sortMovies = function (sort_type, params, res) {
var records_per_page = params.records_per_page;
var offset = params.offset;
var movies = movie.sort_by(sort_type, records_per_page, offset, function(movies){
return res.status(200).json(movies);
});
}

exports.moviesController = {

all: function all(req, res) {
var movies = movie.all(function(movies) {
return res.status(200).json(movies);
});
},

release_date_sort: function release_date_sort(req, res) {
var sort_type = "release_date";
sortMovies(sort_type, req.params, res);
},

title_sort: function title_sort(req, res) {
var sort_type = "title";
sortMovies(sort_type, req.params, res);
},

movie_info: function movie_info(req, res) {
var movie_title = req.params.title;

movie.movie_info(movie_title, function(movie_info) {
return res.status(200).json(movie_info);
});
},

current_customers: function current_customers(req, res) {
var movie_title = req.params.title;

movie.current_customers(movie_title, function(current_customers) {
return res.status(200).json(current_customers);
});
},

past_customers: function past_customers(req, res) {
var movie_title = req.params.title;

movie.past_customers(movie_title, function(past_customers) {
return res.status(200).json(past_customers);
});
},

past_customers_id_sort: function past_customers_id_sort(req, res) {
var movie_title = req.params.title;
var sort_type = "customers.id";

movie.past_customers_sort(movie_title, sort_type, function(past_customers_sorted_by_id) {
return res.status(200).json(past_customers_sorted_by_id);
});
},

past_customers_name_sort: function past_customers_name_sort(req, res) {
var movie_title = req.params.title;
var sort_type = "customers.name";

movie.past_customers_sort(movie_title, sort_type, function(past_customers_sorted_by_name) {
return res.status(200).json(past_customers_sorted_by_name);
});
},

past_customers_checkout_date_sort: function past_customers_checkout_date_sort(req, res) {
var movie_title = req.params.title;
var sort_type = "rentals.check_out";

movie.past_customers_sort(movie_title, sort_type, function(past_customers_sorted_by_checkout_date) {
return res.status(200).json(past_customers_sorted_by_checkout_date);
});
}
}
46 changes: 46 additions & 0 deletions controllers/rentals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use strict";

var Rental = require('../rentals');
var rental = new Rental();

exports.rentalsController = {
all_rentals: function all_rentals(req, res) {
var rentals = rental.all_rentals(function(rentals) {
return res.status(200).json(rentals);
});
},

current_customers: function current_customers(req, res) {
var movie_title = req.params.movie_title;

rental.current_customers(movie_title, function(current_customers){
return res.status(200).json(current_customers);
});
},

rental_log: function rental_log(req, res) {
var movie_title = req.params.movie_title;

rental.rental_log(movie_title, function(rental_log){
return res.status(200).json(rental_log);
});
},

overdue: function overdue(req, res) {
rental.overdue(function(overdue) {
return res.status(200).json(overdue);
});
},

check_out: function check_out(req, res) {
rental.check_out(req.body, function(check_out) {
return res.status(200).json(check_out);
});
},

check_in: function check_in(req, res) {
rental.check_in(req.body, function(check_in) {
return res.status(200).json(check_in);
});
}
};
24 changes: 24 additions & 0 deletions customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use-strict";
var sqlite3 = require('sqlite3').verbose();

function Customer() {
this.table_name = "customers";
}

Customer.prototype = require('./database');

Customer.prototype.current_rentals = function(id, callback) {
// list of current rentals out based on customer id
this.query("SELECT * FROM rentals WHERE customer_id=" + id + " AND check_in IS NULL;", function(res) {
callback(res);
});
};

Customer.prototype.past_rentals = function(id, callback) {
// list of past rentals based on customer id
this.query("SELECT * FROM rentals WHERE customer_id=" + id + " AND check_in IS NOT NULL ORDER BY check_out" + ";", function(res) {
callback(res);
});
};

module.exports = Customer;
Loading