Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
ad34c58
Created fresh node install
lilagrc Sep 15, 2015
acebf38
Changed route names to movies and customers. Added controllers
lilagrc Sep 15, 2015
e2209ba
Adds some pseudo code for routes
lilagrc Sep 15, 2015
3cb9b52
Installed sqlite3
blip-lorist Sep 17, 2015
1adb09e
Created seed and schema files.
blip-lorist Sep 17, 2015
2e860a1
Our schema file generated a dev.db
blip-lorist Sep 17, 2015
ca58149
Started on tests.
blip-lorist Sep 17, 2015
06d0cf1
Created a test db. Seems legit.
blip-lorist Sep 17, 2015
e79f726
Semicolon.
blip-lorist Sep 17, 2015
708e5b2
Added db files to git ignore.
blip-lorist Sep 17, 2015
c67a1bd
Untracking db folder.
blip-lorist Sep 17, 2015
d5bc554
Added schema for cumstomers table
lilagrc Sep 17, 2015
cb5f63a
Added seed code for customers
lilagrc Sep 17, 2015
3a9a956
Added schema for rental table.
lilagrc Sep 17, 2015
5f9dc93
Created a models folder.
blip-lorist Sep 17, 2015
8f45370
Added customer model. Added database.js file. Added first model test.
lilagrc Sep 18, 2015
74d7ccc
Created customer controller method, and WIP on route
lilagrc Sep 18, 2015
d4fe0f6
Updating master
blip-lorist Sep 18, 2015
b03999b
We can now run the npm test command
blip-lorist Sep 18, 2015
e0d43b7
Nodemon is now included in npm start command
blip-lorist Sep 18, 2015
5fa5ba5
Missing brace.
blip-lorist Sep 18, 2015
861947f
Wrote a test function for the module.
blip-lorist Sep 18, 2015
9895ee6
Got our customers controller to collect the json object from our db.
blip-lorist Sep 18, 2015
bbc4a06
Changed variables names so we wouldn't get confused about res.
blip-lorist Sep 18, 2015
139cf52
Removed comments.'
blip-lorist Sep 18, 2015
0f49e81
Removed comments.'
blip-lorist Sep 18, 2015
0633cf7
Added controller method, prototype method, and route for retrieving s…
lilagrc Sep 18, 2015
5f57587
Wrote a offset variable that calculates the amount of records to offs…
blip-lorist Sep 19, 2015
82ebed4
Updated route to include page param, removed excess comments.
blip-lorist Sep 19, 2015
2b1ccde
Refactored schema
lilagrc Sep 19, 2015
a764c2a
Merge pull request #1 from lilagrc/refactor_schema
lilagrc Sep 19, 2015
e83d9dd
Added movie model, controller methods for index and subset, and routes
lilagrc Sep 19, 2015
47c93ce
Merge pull request #2 from lilagrc/all_movies
lilagrc Sep 19, 2015
7b41470
Merge pull request #3 from lilagrc/lk/pagination
Sep 19, 2015
eb59de1
Fixed pagination bug.
blip-lorist Sep 21, 2015
f0b03fa
Pagination for movies.
blip-lorist Sep 21, 2015
771fb84
Added a comment about what our customer id lookup should do.
blip-lorist Sep 21, 2015
54cc8ba
Rentals seed data.
blip-lorist Sep 21, 2015
46f1c28
Merge pull request #4 from lilagrc/lk/pagination
Sep 21, 2015
8b6a8ae
Added available column to movies table. Added currently rented route …
lilagrc Sep 21, 2015
5a19f07
WIP customer history query.
blip-lorist Sep 21, 2015
a2a5619
Endpoint and query for customers who have checked out a specific movi…
blip-lorist Sep 21, 2015
9117681
Added route, query for list of past customers using movie title
lilagrc Sep 21, 2015
5e4c3c5
Rentals routes and model.
blip-lorist Sep 21, 2015
44d2881
Rental routes.
blip-lorist Sep 21, 2015
0ce4c1f
Rental endpoint and query for looking up a single movie by title.
blip-lorist Sep 21, 2015
0fa87e4
Updated to-do list.
blip-lorist Sep 21, 2015
de08676
Added route and methods to return list of customers with current movi…
lilagrc Sep 21, 2015
fe19c05
WIP on overdue customer endpoint
lilagrc Sep 21, 2015
43ddc7c
Resolved db_cleaner issues.
blip-lorist Sep 22, 2015
c0e7317
Merge pull request #5 from lilagrc/lk/customer-model-tests
Sep 22, 2015
7309154
WIP on returning overdue customers
lilagrc Sep 22, 2015
3be0604
adds functionality for returning overdue customers
lilagrc Sep 22, 2015
8c8c61c
Added model tests for movies and customers
lilagrc Sep 23, 2015
47fe040
A customer's history can now be found using a single query, yay.
blip-lorist Sep 23, 2015
c8230dc
Merge pull request #6 from lilagrc/lk/customer_history
Sep 23, 2015
57547b7
Merge branch 'lone_gunmen/master' of github.com:lilagrc/C3Projects--V…
lilagrc Sep 23, 2015
d347f80
Merge pull request #7 from lilagrc/movie_tests
lilagrc Sep 23, 2015
303d2e1
WIP on post for new rental
lilagrc Sep 23, 2015
43bf9fa
Added a duedate column.
blip-lorist Sep 23, 2015
78d714a
Posting new rentals to the database.
blip-lorist Sep 23, 2015
cf4495c
Updated our sqlite query for creating a new rental record.
blip-lorist Sep 23, 2015
677ef98
added two more tests for model methods:
lilagrc Sep 23, 2015
8e489e8
Completed the rentals route and functions for processing new rentals.
blip-lorist Sep 23, 2015
0533fc0
Merge pull request #8 from lilagrc/post_req
Sep 23, 2015
a78dce4
Merge pull request #9 from lilagrc/moar_tests
lilagrc Sep 23, 2015
4368543
Updated query to display and sort by checked out date. Results exclud…
blip-lorist Sep 24, 2015
60fa210
Merge pull request #10 from lilagrc/lk/customer_history
Sep 24, 2015
a10ed3d
Added more instance method tests
lilagrc Sep 24, 2015
01060ec
WIP on rental instance method tests
lilagrc Sep 24, 2015
dcd027e
Got some endpoint tests started.
blip-lorist Sep 24, 2015
fae2053
Merge pull request #11 from lilagrc/lk/endpoint-tests
Sep 24, 2015
cf5b148
changed new rental to a post request and created function inception
lilagrc Sep 24, 2015
7a2d526
Route and endpoint for checking in videos.
blip-lorist Sep 24, 2015
0585a90
Added endpoint tests for movies controller:
lilagrc Sep 24, 2015
61a9cbd
WIP on rentals get endpoint tests
lilagrc Sep 24, 2015
303328e
WIP on rental controller tests
lilagrc Sep 24, 2015
fb101a7
Updated page routes for clarity.
blip-lorist Sep 24, 2015
d093fe8
Updated endpoint to include page.
blip-lorist Sep 24, 2015
0e17497
Updated the test db seed data.
blip-lorist Sep 24, 2015
5c125ef
Fixing merge conflict.
blip-lorist Sep 24, 2015
62c66fa
Fixed seed data to accomodate registered dates.
blip-lorist Sep 24, 2015
8400633
Updated controller tests for subsets.
blip-lorist Sep 24, 2015
74ced54
WIP on rental controller tests
lilagrc Sep 24, 2015
f7e81a0
Resolved merge conflicts.
blip-lorist Sep 24, 2015
c09fadc
Merge pull request #12 from lilagrc/lk/tests
Sep 24, 2015
e313bc1
Fixed rentals controller tests
lilagrc Sep 24, 2015
2997e31
Fixed some failing tests after updating test seed data. WIP on post e…
lilagrc Sep 25, 2015
9c29139
WIP rental model tests.
blip-lorist Sep 25, 2015
4da33fa
Merge pull request #13 from lilagrc/lk/tests
Sep 25, 2015
82042f6
You can now use underscores to indicate spaces in titles.
blip-lorist Sep 25, 2015
64e4e45
You can now use underscores to indicate spaces in titles.
blip-lorist Sep 25, 2015
a1f83bf
Documented movies and rental endpoints.
blip-lorist Sep 25, 2015
98577cc
Merge pull request #14 from lilagrc/lk/spaces
Sep 25, 2015
68a49f0
Added final endpoint tests
lilagrc Sep 25, 2015
ea125fd
Merge branch 'lone_gunmen/master' of github.com:lilagrc/C3Projects--V…
lilagrc Sep 25, 2015
77f4f35
Merge pull request #15 from lilagrc/rc_tests
lilagrc Sep 25, 2015
2a5b828
updated readme
lilagrc Sep 25, 2015
f8a57dd
Merge pull request #16 from lilagrc/rc_tests
lilagrc 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
node_modules
db
78 changes: 61 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,47 @@ The API you build should have the following capabilities. The schema of your dat
- There is not an authentication requirement for this project; assume all users interacting with the API are video store employees.

### Customers
- Retrive a list of all customers
- Retrive a subset of customers
- Given a sort column, return _n_ customer records, offset by _p_ records (this will be used to create "pages" of customers)
- Sort columns are
DONE- Retrive a list of all customers
DONE- Retrive a subset of customers
DONE- Given a sort column, return _n_ customer records, offset by _p_ records (this will be used to create "pages" of customers)
DONE- Sort columns are
- `name`
- `registered_at`
- `postal_code`
- Given a customer's `id`...
- List the movies they _currently_ have checked out
DONE- List the movies they _currently_ have checked out
- List the movies a customer has checked out in the past
- ordered by check out date
- includes return date

### Movies
- Retrieve a list of all movies
- Retrieve a subset of movies
- Given a sort column, return _n_ movie records, offset by _p_ records (this will be used to create "pages" of movies)
- Sort columns are
DONE- Retrieve a list of all movies
DONE- Retrieve a subset of movies
DONE- Given a sort column, return _n_ movie records, offset by _p_ records (this will be used to create "pages" of movies)
DONE- Sort columns are
- `title`
- `release_date`
- Given a movie's `title`...
- Get a list of customers that have _currently_ checked out a copy of the film
- Get a list of customers that have checked out a copy _in the past_
DONE- Get a list of customers that have _currently_ checked out a copy of the film
DONE- Get a list of customers that have checked out a copy _in the past_
- ordered by customer `id`
- ordered by customer `name`
- ordered by check out date

### Rental
- Look a movie up by title to see
- DONE Look a movie up by title to see
- it's synopsis
- release date
- and inventory total
- Know if a movie has any inventory available to rent
- See a list of customers that have _currently_ checked out any of the movie's inventory
- Given a customer's `id` and a movie's `title` ...
- DONE Know if a movie has any inventory available to rent
- DONE See a list of customers that have _currently_ checked out any of the movie's inventory
- DONE Given a customer's `id` and a movie's `title` ...
- "check out" one of the movie's inventory to the customer
- Establish a return date
- Charge the customer's account (cost up to you)
- "check in" one of customer's rentals
- DONE "check in" one of customer's rentals
- return the movie to its inventory
- See a list of customers with overdue movies
- DONE See a list of customers with overdue movies

### Interface
- This part of the project is purely an API; all interactions should happen over HTTP requests. There is no front-end, user-facing interface.
Expand All @@ -93,3 +93,47 @@ The API you build should have the following capabilities. The schema of your dat
- We will use [Mocha](https://mochajs.org/) for tests.
- There isn't a coverage requirement for this project, beyond demonstrating that every endpoint is covered by some manner of tests.

### Things to fix
- accomadate white space in 'given a movie's title' endpoints
- account for negative customer balances
- add late fees?
- account for negative availability
- possibly refactor database.js

# Endpoints

## Movies

- Show all movies:
http://localhost:3000/movies
- Look up past rentals for a movie: http://localhost:3000/movies/alien/past_rentals/id
- Look up current rentals for a movie
http://localhost:3000/movies/psycho/current_rentals
- Pagination for title
http://localhost:3000/movies/title/page1
______

## Customers
-Show all customers:
http://localhost:3000/customers
- Loop at subset of customers sorted by name, registered at, postal_code
http://localhost:3000/customers/name/page1
- Show customers current rentals
http://localhost:3000/customers/1/current_rentals
- Customers past rentals
http://localhost:3000/customers/2/current_rentals


## Rentals
- Check out a new title
curl -X POST http://localhost:3000/rentals/new_rental/4/the_exorcist
- Check in a title
curl -X PUT http://localhost:3000/rentals/check_in/4/the_exorcist
- Check overdue rentals
http://localhost:3000/rentals/overdue
- Look at the movie's details
http://localhost:3000/rentals/the_exorcist
- Find a movie's current customer rentals
http://localhost:3000/rentals/the_exorcist/customers


64 changes: 64 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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 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')));


var routes = require('./routes/movies');
app.use('/movies', routes);

var customers = require('./routes/customers');
app.use('/customers', customers);

var rentals = require('./routes/rentals');
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);
}
43 changes: 43 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use strict";

var Customer = require('../models/customer');

exports.customersController = {
index: function index(req, res) {

var customer = new Customer();

customer.find_all(function(err, record) {
res.status(200).json({ all_customers: record });
})
},

subset: function subset(req, res, column, pageNumber) {

var customer = new Customer();
//pagination begins at 0
var offset = pageNumber * 50;

customer.find_subset(column, 50, offset, function(err, record) {
res.status(200).json({ customer_subset: record });
})
},

current_rentals: function current_rentals(req, res, customer_id) {

var customer = new Customer();

customer.customer_rentals(customer_id, function(err, record){
res.status(200).json({ current_rentals: record });
})
},

rental_history: function rental_history(req, res, customer_id) {

var customer = new Customer();

customer.customer_history(customer_id, function(err, record){
res.status(200).json({ rental_history: record });
})
}
}
53 changes: 53 additions & 0 deletions controllers/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";

var Movie = require('../models/movie');

function titleSpaces(title) {
return title.replace("_", " ");
}

exports.moviesController = {

index: function index(req, res) {

var movie = new Movie();

movie.find_all(function(err, record) {
res.status(200).json({ all_movies: record });
})
},

subset: function subset(req, res, column, pageNumber) {

var movie = new Movie();

//pagination begins at 0
var offset = pageNumber * 50;

movie.find_subset(column, 50, offset, function(err, record) {
res.status(200).json({ movie_subset: record });
})
},

current_rentals: function current_rentals(req, res, movie_title) {

movie_title = titleSpaces(movie_title);

var movie = new Movie();

movie.movie_current_customers(movie_title, function(err, record) {
res.status(200).json({ movie_current_customers: record });
})
},

past_rentals: function past_rentals(req, res, movie_title, column) {

movie_title = titleSpaces(movie_title);

var movie = new Movie();

movie.movie_past_customers(movie_title, column, function(err, record) {
res.status(200).json({ movie_past_customers: record });
})
}
}
Loading