Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
140 commits
Select commit Hold shift + click to select a range
8d4699e
added route zomg
rishallen Jun 14, 2016
502a553
added massive dependency along with the customized script for the dat…
rishallen Jun 14, 2016
99d09db
created a schema as a part of the customized scripts.
rishallen Jun 14, 2016
c9fc56f
added '*.log' to gitignore.
rishallen Jun 14, 2016
fe63389
created two tables, history and rentals.
rishallen Jun 15, 2016
2a14601
adjusted value type in customer table from integer to deciaml for acc…
rishallen Jun 15, 2016
1c48825
we updated the script seed task and added it to the reset script.
rishallen Jun 15, 2016
6d44257
created an algorithm for seeding the data tables.
rishallen Jun 15, 2016
0133392
seeded the Rentals table
Jun 15, 2016
c5cb407
Added 'status' as INDEX in the rentals schema
Jun 15, 2016
fc9706b
fixed a bug that was not capturing the id of the movie to populate in…
Lisa-Sano Jun 16, 2016
065202a
removed unnecessary console.logs used to test seeding
Lisa-Sano Jun 16, 2016
8b28572
made notes to identify the steps taken in the request process.
rishallen Jun 16, 2016
4693e9e
created controllers and models for movies, customers, and rentals. de…
Lisa-Sano Jun 16, 2016
0b18c5c
added massive, connection, and db setup to this file. Changed the loc…
rishallen Jun 16, 2016
3824790
created the customers.all function and flow.
rishallen Jun 16, 2016
b5bc62a
set basic functionality of the routes and models for movies and rentals.
rishallen Jun 16, 2016
95a5171
added semicolons
rishallen Jun 16, 2016
8162a94
requiring app and setting app for the database.
rishallen Jun 16, 2016
7319eb2
created test
rishallen Jun 16, 2016
ed2ab85
added the movies flow for .all request and started on rentals show.
rishallen Jun 16, 2016
def45be
added sort route and functionality to movies
Lisa-Sano Jun 17, 2016
1eeb907
created tests for sort by column
Jun 17, 2016
4d837ac
added the flow to send requests and retrieve json response.
rishallen Jun 17, 2016
23280a7
apart of the flow request and response to json.
rishallen Jun 17, 2016
119ceb5
added rentals seeds
Jun 17, 2016
1dc3d4a
removed seed file for rentals. unnecessary
Lisa-Sano Jun 17, 2016
a86b233
fixed bug with populating rentals table. assign a few customers to re…
Lisa-Sano Jun 17, 2016
6909f39
working on the customers movie call
rishallen Jun 17, 2016
f3f25ef
Merge branch 'master' into customerspage
rishallen Jun 17, 2016
03fb910
deleted reference to rental seed file since it was removed
Lisa-Sano Jun 17, 2016
6c01dc7
Merge branch 'master' into customerspage
rishallen Jun 17, 2016
7d8f6d8
when given a movie title in movies/:title/current, gives a list of cu…
Lisa-Sano Jun 17, 2016
41ba9d0
added some history seed data
Lisa-Sano Jun 17, 2016
0d3b09b
changed method and variable names to be more descriptive
Lisa-Sano Jun 17, 2016
2b6f758
added a method, current to find the rentals of a single customer id a…
rishallen Jun 17, 2016
5486691
fixed a merge conflict within the customers controller.
rishallen Jun 17, 2016
3b20c69
can find history of all past rentals for a specific movie
Lisa-Sano Jun 17, 2016
b89b146
fixed colon error
rishallen Jun 17, 2016
51252e2
uncommment routes for Rantals
Jun 17, 2016
4cc4653
added '/:title endpoint
Jun 17, 2016
0f40cf6
added find_movie method that calls Movies.find, Rentals.available, an…
Jun 17, 2016
d51dbda
created Rentals.available that returns a nummber, the length of the a…
Jun 17, 2016
10fe85a
solved conflicts
Jun 17, 2016
db21a3e
replace the massive setup for the fancy two lines of code
Jun 17, 2016
e6c5a15
coment out a non-used route
Jun 17, 2016
beb2bcd
added the length
Jun 18, 2016
3d3a88b
updated seeds so the same customers didn't check out multiple copies …
Lisa-Sano Jun 19, 2016
f19da05
updated the sql query to use inner joins between movies, rentals, and…
Lisa-Sano Jun 19, 2016
1bea08d
fixed merge conflicts
Lisa-Sano Jun 19, 2016
8766c44
replaced nested queries using different model methods with an inner j…
Lisa-Sano Jun 19, 2016
4caca95
only displays name, phone number, and account credit for each custome…
Lisa-Sano Jun 19, 2016
484a56d
removed a bunch of commented-out code no longer in use
Lisa-Sano Jun 19, 2016
2dd6f0e
fixed merge conflict
Lisa-Sano Jun 19, 2016
e21897d
fixed conflict
Jun 19, 2016
225b42c
add functionality for sorting customer history information either by …
Lisa-Sano Jun 19, 2016
5b52bd9
added status codes to json responses for /movies/ routes
Lisa-Sano Jun 20, 2016
5e0bcec
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
Jun 20, 2016
c40ce34
See a list of customers that have currently checked out any of the mo…
Jun 20, 2016
74129c6
moved sql code for finding customers that currently have a given movi…
Lisa-Sano Jun 20, 2016
5eb45ae
added the history function
rishallen Jun 20, 2016
8dc5e53
change the name of the controller for one more semantic current_custo…
Jun 20, 2016
76b10c3
made merge changes to the history model
rishallen Jun 20, 2016
ace87c3
refactor find_customers_by_title
Jun 20, 2016
fdcebcc
refactor the object reteurned in /rentals/Jaws. The status is include…
Jun 20, 2016
1a5a585
set istanbul
Jun 20, 2016
f766f18
removed history model file (not being used)
Lisa-Sano Jun 20, 2016
f343231
added SQL files that have the inner join scripts to get customer info…
Lisa-Sano Jun 20, 2016
7048b8f
call .sql files in db/sql/movies instead of having SQL hard-coded (fo…
Lisa-Sano Jun 20, 2016
e77258e
fixed merge conflict
Lisa-Sano Jun 20, 2016
4b9eac0
refactored to DRY up callbacks
Lisa-Sano Jun 20, 2016
2f2277e
changed method name from sort_by_day to sort_by since it can also sor…
Lisa-Sano Jun 21, 2016
20ebb10
tests for movies model
Lisa-Sano Jun 21, 2016
465cb2f
added basic controller tests
Jun 20, 2016
1f9ebcc
deleted unsused get_customer_ids
Jun 20, 2016
fad591e
fixed bug tht calculates the copies available
Jun 21, 2016
150c125
ettempted to write some model tests
Jun 21, 2016
a32d540
added file to the models directory, fixed the test
Jun 21, 2016
1be5b99
added more models test and extended the controllers tests
Jun 21, 2016
8d20e52
added tests for enpoint /:title/customers
Jun 21, 2016
931c5a0
working on flow for customer history flow.
rishallen Jun 21, 2016
8b6ed98
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
rishallen Jun 21, 2016
8ea896b
fixed merge conflicts
rishallen Jun 21, 2016
0528ccf
added overdue column to history table, and update the seed file
Jun 21, 2016
94ad964
added a conditional that checks the request and makes sure there are …
rishallen Jun 21, 2016
37c99e7
first atempt to do post requests
Jun 21, 2016
cf07dd7
conflicts
Jun 21, 2016
612129d
more attempting post request, for now the update, apdates all the(mov…
Jun 21, 2016
dc97e66
istanbul does not count spec folders anymore
Jun 21, 2016
2cd5e6b
addded the SQL for updating into its own file. It is succesfully upda…
Jun 22, 2016
dba3be4
checkout.sql returns a rental instance to the rental controller which…
Lisa-Sano Jun 22, 2016
b2a1b31
removed distinct from select clause so that all entries are found eve…
Lisa-Sano Jun 23, 2016
f7db5a1
added a default order_by for customer history. if an invalid sort opt…
Lisa-Sano Jun 23, 2016
fc52d33
added tests for movies model
Lisa-Sano Jun 23, 2016
b8c803a
changed to status 500 for errors
Lisa-Sano Jun 23, 2016
fc33b0c
added tests for the movies controller
Lisa-Sano Jun 23, 2016
804ff1e
DRY up movies controller. if sort column for movies/sort/:column path…
Lisa-Sano Jun 23, 2016
4491e30
removed a test
Lisa-Sano Jun 24, 2016
2881e5c
crerating json api flow.
rishallen Jun 24, 2016
2c72efa
Merge branch 'master' into customerspage
rishallen Jun 24, 2016
1b99b53
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
rishallen Jun 24, 2016
c505728
#create_record returns an instance of History
Lisa-Sano Jun 24, 2016
305e238
added tests for history model
Lisa-Sano Jun 24, 2016
357c165
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
Lisa-Sano Jun 24, 2016
2c2d322
one test
Jun 24, 2016
71822d3
trying to update the customer account
Jun 24, 2016
d4cf818
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
Jun 24, 2016
0e3961f
removed distinct from select clause so that all entries are found eve…
Lisa-Sano Jun 23, 2016
cc9435d
added a default order_by for customer history. if an invalid sort opt…
Lisa-Sano Jun 23, 2016
2282f59
added tests for movies model
Lisa-Sano Jun 23, 2016
53b3f3d
changed to status 500 for errors
Lisa-Sano Jun 23, 2016
64aedb6
added tests for the movies controller
Lisa-Sano Jun 23, 2016
37a54e5
DRY up movies controller. if sort column for movies/sort/:column path…
Lisa-Sano Jun 23, 2016
fa03731
removed a test
Lisa-Sano Jun 24, 2016
188f347
#create_record returns an instance of History
Lisa-Sano Jun 24, 2016
f485379
added tests for history model
Lisa-Sano Jun 24, 2016
58e0f9b
Merge branch 'practice'
Jun 24, 2016
6c3a17a
added status codes customers controller methods and updated history m…
Lisa-Sano Jun 24, 2016
ea1a682
added a space
Lisa-Sano Jun 24, 2016
276aec5
added overdue functionality. get customer name, movie title, checkout…
Lisa-Sano Jun 24, 2016
97cfe56
forgot to add with last commit. overdue functionality for rentals
Lisa-Sano Jun 24, 2016
2fb800d
added status code to json response for overdue path
Lisa-Sano Jun 24, 2016
8addb9c
mark_as_checkout and updatecustomer working crispy
Jun 24, 2016
d912c35
updated history seed file to include movies currently rented in renta…
Lisa-Sano Jun 24, 2016
4b7f7c0
overdue method returns results of rentals that have a status 'rented'…
Lisa-Sano Jun 24, 2016
780df87
dates that are entered when inserting new history records in the tabl…
Lisa-Sano Jun 24, 2016
89cf0e5
removed overdue column from the history table (not needed)
Lisa-Sano Jun 24, 2016
5b0212e
updated tests to reflect changes in seed files
Lisa-Sano Jun 24, 2016
4d81bb4
/rentals/:title/return/:id
Jun 24, 2016
8c7d072
added history tests
Lisa-Sano Jun 24, 2016
62e30f5
created an html view and changed to json file vs js file
rishallen Jun 24, 2016
c6a18f5
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
rishallen Jun 24, 2016
928f188
fixed conflics
Jun 24, 2016
1251668
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
Jun 24, 2016
d24fdbf
delete a console.log
Jun 24, 2016
8c01984
added some more tests
rishallen Jun 24, 2016
90b6453
Merge branch 'master' of github.com:rishallen/VideoStoreAPI
rishallen Jun 24, 2016
932ecf2
added more tests in the model
rishallen Jun 24, 2016
bf35bbf
fixed some styling issues, attempt to make test fot posr request, it …
Jun 25, 2016
fad219e
added more tests to the rentals model, edited some of the controllers
Jun 25, 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.DS_Store
node_modules/
*.log
coverage/
22 changes: 19 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ 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/videoStore";
// the node module that is used to access the database
var db = massive.connectSync({connectionString: connectionString});
// this gives me a way to grab the database from the code, like in the model
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')));
Expand All @@ -21,8 +27,18 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

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

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

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

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

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
Expand Down
97 changes: 97 additions & 0 deletions controllers/customers_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
var Customers = require("../models/customers");
var Rentals = require("../models/rentals");
var History = require("../models/history");

var CustomersController = {
index: function(req, res, next) {
Customers.all(function(error, customers) { // this is a callback
if(error) {
var err = new Error("Error retrieving customers list:\n" + error.message);
err.status = 500;
next(err);
} else {
var obj = {};
if (customers.length === 0) {
obj["status"] = 204;
} else {
obj["status"] = 200;
}
}
obj["customers"] = customers;
res.json(obj);
});
},

// the word phone breaks the code:
sort: function(req, res, next) {
if(req.params.column === "name" || req.params.column === "registered_at" || req.params.column === "postal_code") {

//Send in an ORDER clause and a LIMIT with OFFSET
var options = {
limit : req.query.n,
order : req.params.column,
offset: req.query.p
};
// products ordered in descending fashion
// takes 2 parameters
// options and the callback fucntion
Customers.sort_by(options, function(error, customers) { // this will return and array of customers
if(error) {
var err = new Error("No such customer");
err.status = 404;
next(err);
} else {
var obj = {};
if (customers.length === 0) {
obj["status"] = 204;
} else {
obj["status"] = 200;
}
obj["customers"] = customers;
res.json(obj);
}
});
} else {
var obj = {};
obj["status"] = 400;
obj["message"] = "invalid request";
res.json(obj);
}
},
// this is a property whose value is a function (this is now a method)
// this is the response from node
current: function(req, res, next) {
//model has a find method that takes in 2 arguments (id, callback function)
Rentals.find_by_customer(req.params.id, function(error, rentals) {
if(error) {
var err = new Error("No such account");
err.status = 404;
next(err);
} else {
res.json(rentals); // write out the rentals as json
}
});
},

history: function(req, res, next) {
//model has a find method that takes in 2 arguments (id, callback function)
History.getPastRentalHistory(req.params.id, function(error, history) {
if(error) {
var err = new Error("No history at this store");
err.status = 404;
next(err);
} else {
var obj = {};
if (history.length === 0) {
obj["status"] = 204;
} else {
obj["status"] = 200;
}
obj["history"] = history;
res.json(obj); // write out the history as json
}
});
}
};

module.exports = CustomersController;
21 changes: 21 additions & 0 deletions controllers/index_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var doc = require ("../doc.json");


var IndexController = {
locals: {
documentation: doc
},

getJSON: function (req, res, next) {
res.json(200, doc);
},

getHTML: function(req, res, next) {
// console.log(string_docs);
res.render('docs', IndexController.locals);
}
};



module.exports = IndexController;
68 changes: 68 additions & 0 deletions controllers/movies_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
var Movies = require("../models/movies");
var Rentals = require('../models/rentals');
var Customers = require('../models/customers');

var MoviesController = {
index: function(req, res, next) {
Movies.all(callback(res, "movies"));
},

sort: function(req, res, next) {
var order_by = req.params.column;
var options = {
limit : req.query.n,
offset: req.query.p
};

if (order_by === "release_date" || order_by === "release-date") {
options["order"] = "release_date";
} else if (order_by === "title") {
options["order"] = "title";
} else {
options["order"] = "id";
}

Movies.sort_by(options, callback(res, "movies"));
},

current: function(req, res, next) {
var movie = req.params.title;
Movies.find_customers_by_title(movie, callback(res, "customers"));
},

history: function(req, res, next) {
var movie = req.params.title;
var column = req.params.column;
var order_by;

if (column === 'name') {
order_by = 'name';
} else if (column === 'checkout_date') {
order_by = 'checkout_date';
}

Movies.find_customers_by_history(movie, order_by, callback(res, "customers"));
}
};

function callback(res, type) {
return function(error, result) { // this is a callback
if(error) {
var err = new Error("Error retrieving results:\n" + error.message);
err.status = 500;
res.render(err);
} else {
var obj = {};
if (result.length === 0) {
obj["status"] = 204;
} else {
obj["status"] = 200;
}
obj[type] = result;
res.json(obj);
}
}
}

module.exports = MoviesController;

123 changes: 123 additions & 0 deletions controllers/rentals_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
var Rentals = require('../models/rentals');
var Movies = require("../models/movies");
var Customers = require("../models/customers");
var History = require("../models/history");

var RentalsController = {

find_movie: function(req, res, next) {
var movie = req.params.title;

Movies.find(movie, function(error, found_movie) {
if(error) {
var err = new Error("No such movie");
err.status = 404;
next(err);
} else {
obj = {}
obj['status'] = 200;
obj['Movie Info'] = {};
obj['Movie Info']['Synopsis'] = found_movie.overview;
obj['Movie Info']['Release Date'] = found_movie.release_date;
obj['Movie Info']['Total Inventory'] = found_movie.inventory;
Rentals.available(found_movie.id, function(err, number){
obj['Movie Info']['Available Inventory'] = number
res.json(obj);
});
}
});
},

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

Rentals.find_customers_by_title(movie, function(error, customers) {
if(error) {
var err = new Error("No such movie");
err.status = 404;
next(err);
} else {
var obj = {};
if (customers.length === 0) {
obj["status"] = 204;
} else {
obj["status"] = 200;
}
obj["customers"] = customers;
res.json(obj);
}
})
},

checkout: function(req, res, next) {
var customer_id = req.params.id;
var movie = req.params.title;


Rentals.mark_as_checkout (movie, customer_id, function(error, rental_array, customer_updated) {
if(error) {
var err = new Error(error.message);
err.status = 404;
next(err);
} else {
var rental_id = rental_array[0].id
History.create_record(rental_id, customer_id, function(error, history_result) {
if(error) {
var err = new Error(error.message);
err.status = 404;
next(err);
} else {
obj = {}
obj["Status"] = 200;
obj["Message"] = "Checkout has been processed succesfully"
obj["Return day"] = history_result["return_date"]
obj["Customer's Name"] = customer_updated[0]["name"]
obj["Customer's Credit"] = customer_updated[0]["account_credit"]

res.json(obj);
}
});
}
});
},

// include customer name, movie title, check-out date, and return date
overdue: function(req, res, next) {
Rentals.get_overdue(function(error, customers) {
if(error) {
var err = new Error(error.message);
err.status = 500;
next(err);
} else {
obj = {};
if (customers.length === 0) {
obj["status"] = 204;
} else {
obj["status"] = 200;
}
obj["customers"] = customers
res.json(obj);
}
})
},

return_a_rental: function(req, res, next) {
var customer_id = req.params.id;
var movie = req.params.title;
Rentals.return_rental(customer_id, movie, function(error, updated_rental) {
if(error) {
var err = new Error(error.message);
err.status = 404;
next(err);
} else {
obj = {}
obj["Status"] = 200;
obj["Message"] = "Return has been processed succesfully"
obj["Rental info"] = updated_rental[0]
res.json(obj);
}
})
}
};

module.exports = RentalsController;
Loading