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

VideoStoreAPI #10

Open
wants to merge 107 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
70739f7
added scripts
nlcurry Jun 14, 2016
c350956
added setup files
nlcurry Jun 14, 2016
20cb8f8
added load_schema file
nlcurry Jun 14, 2016
ef62fa5
made table for movies
nlcurry Jun 14, 2016
e3075a3
changed db name
nlcurry Jun 14, 2016
412e985
changed db name
nlcurry Jun 14, 2016
cd8b916
created rentals join table and customer table
nlcurry Jun 14, 2016
623dd57
created indexes
nlcurry Jun 14, 2016
40ab38a
added indeces for rentals table
nlcurry Jun 14, 2016
9d0f0ac
added controller files
nlcurry Jun 14, 2016
a03c7d6
added files to routes
nlcurry Jun 14, 2016
37067ff
added files for routes
nlcurry Jun 14, 2016
01d209a
defined routes for new route files
nlcurry Jun 14, 2016
b201316
add script for seed
nlcurry Jun 15, 2016
8c8abc9
added serial to primary key
nlcurry Jun 15, 2016
3c4a022
zomg
nlcurry Jun 15, 2016
3ebced8
created loop for movie table seeding
nlcurry Jun 15, 2016
a0e724f
Update rentals schema to use due_date instead or return_date;
sophiabaldonado Jun 15, 2016
9a4df2e
add seed data for rentals table;
sophiabaldonado Jun 15, 2016
c0acf6f
Add seed rentals loop to seed task;
sophiabaldonado Jun 15, 2016
f84a4a1
npm debug log;
sophiabaldonado Jun 15, 2016
dddeb2b
Placeholder routes;
sophiabaldonado Jun 15, 2016
530759d
Fix seed task so that it ends the process when all data is seeded;
sophiabaldonado Jun 15, 2016
108f85e
clean up seeding task;
sophiabaldonado Jun 15, 2016
8a178dc
Capitalize controller names;
sophiabaldonado Jun 16, 2016
2532a2a
Setup skeleton for controllers with functions;
sophiabaldonado Jun 16, 2016
248205f
Fix customer routes so it doesn't say customers because that's specif…
sophiabaldonado Jun 16, 2016
e2f7997
made model files and added customer.all
nlcurry Jun 16, 2016
375f1da
added index function
nlcurry Jun 16, 2016
89c65c9
change db query
nlcurry Jun 16, 2016
081725a
fix typo
nlcurry Jun 16, 2016
8151f8a
initialize db
nlcurry Jun 16, 2016
e62b4ae
finished sortby and index function for customers
nlcurry Jun 16, 2016
463fe95
added seed to db:reset
nlcurry Jun 16, 2016
7523559
ignoring some lines
nlcurry Jun 16, 2016
3e69ff8
ignoring some line pt 2
nlcurry Jun 16, 2016
b5ef866
created sortbyname function
nlcurry Jun 16, 2016
131c837
enable movie routes
nlcurry Jun 16, 2016
07215f6
made index function for movies
nlcurry Jun 16, 2016
c30a4aa
finished all sortbys for customer
nlcurry Jun 16, 2016
8210c54
added sortby method
nlcurry Jun 17, 2016
55590cb
added sortby method
nlcurry Jun 17, 2016
c86f1f5
uncommented sort route
nlcurry Jun 17, 2016
5c6fcbd
deleted comments
nlcurry Jun 17, 2016
c9bdf3f
working on current function
nlcurry Jun 17, 2016
a66e099
added more records to rental seed
nlcurry Jun 17, 2016
36b8ca6
moved function from customer to rental
nlcurry Jun 17, 2016
9738d6f
uncommented route
nlcurry Jun 17, 2016
bab8874
comment out history function
nlcurry Jun 17, 2016
ceaf128
fixed query for rentals
nlcurry Jun 17, 2016
1d65a2a
route, action and model query for customers/history path;
sophiabaldonado Jun 17, 2016
561f4a2
route, controller action, and model query for customersWithMovie chec…
sophiabaldonado Jun 17, 2016
d38a09e
routes, action, queries for movie title rental history sorted by name…
sophiabaldonado Jun 17, 2016
2b5c889
uncommented rental routes
nlcurry Jun 17, 2016
9d65f38
uncommented rental routes
nlcurry Jun 17, 2016
2c361ce
added movie lookup method
nlcurry Jun 17, 2016
331ead8
added method for rental info
nlcurry Jun 17, 2016
81a42a9
Update script to use istanbul for test coverage;
sophiabaldonado Jun 20, 2016
b5b83b7
Setup a view file for the docs and include new routes;
sophiabaldonado Jun 20, 2016
a32ee00
Merge branch 'master' of github.com:nlcurry/VideoStoreAPI
sophiabaldonado Jun 20, 2016
3e39da0
Created json file for docs;
sophiabaldonado Jun 20, 2016
241ee8b
Added some placeholder text for docs view and styled;
sophiabaldonado Jun 20, 2016
49f365b
Rentals overdue action, route, and query;
sophiabaldonado Jun 20, 2016
fb89d72
added function for currently checked out movies
nlcurry Jun 20, 2016
da6a0f2
uncommented and change function name for rental route
nlcurry Jun 20, 2016
02608dd
added currentlycheckedout function
nlcurry Jun 20, 2016
7e2814e
Checkout adds a record into rentals table with correct ids and dates;
sophiabaldonado Jun 20, 2016
23bf75a
Checkout subtracts one from the movie's inventory;
sophiabaldonado Jun 20, 2016
5a19a01
Checkout returns the new record's info;
sophiabaldonado Jun 20, 2016
beebdf2
Created rental return route, query, and action;
sophiabaldonado Jun 21, 2016
752e938
Added a note about how we're getting the data for id;
sophiabaldonado Jun 21, 2016
623f974
started the docs.json file;
sophiabaldonado Jun 21, 2016
5868946
Set up seperate dev and test environments with seperate databased;
sophiabaldonado Jun 21, 2016
d654c62
Change test script so it doesn't instrument test files;
sophiabaldonado Jun 22, 2016
58b2bac
Create model test files;
sophiabaldonado Jun 22, 2016
74e2d4a
model ovie testing. NOT WORKING
nlcurry Jun 22, 2016
3ab327e
got rid of consolge.log
nlcurry Jun 23, 2016
dafbb14
added coverage script
nlcurry Jun 23, 2016
7c20efb
added tests for customers.all
nlcurry Jun 23, 2016
1eaf8a9
something happened to npm-debug log
nlcurry Jun 23, 2016
a927554
added tests for sortby, customerswithmovie, and rentedthismovie funct…
nlcurry Jun 23, 2016
cb9bc25
added test for currentlycheckedout function
nlcurry Jun 23, 2016
0b93732
added error tests for sortby and customers with movie. reached 90%cov…
nlcurry Jun 23, 2016
b308127
Movie Model tests at 73%;
sophiabaldonado Jun 23, 2016
d1f14ac
added currentcheckedout function tests
nlcurry Jun 23, 2016
3a9f109
added tests for the rest of rental functions
nlcurry Jun 23, 2016
4d0d87e
Movies model is 90% covered;
sophiabaldonado Jun 23, 2016
7bc1c07
Resolve conflict in movie spec;
sophiabaldonado Jun 23, 2016
c73ca4e
added empty files for controller testing
nlcurry Jun 23, 2016
e9f073c
finish up rentas
nlcurry Jun 23, 2016
15290c3
added tests for index and sortby function
nlcurry Jun 23, 2016
036b348
got rid of console.log
nlcurry Jun 23, 2016
8116635
got rid of console.log
nlcurry Jun 23, 2016
0b867fe
got rid of console.logs
nlcurry Jun 23, 2016
c8ded50
Tested bad request;
sophiabaldonado Jun 24, 2016
963dfb3
Commented out console.logs;
sophiabaldonado Jun 24, 2016
244eb6f
Added some movie controller tests;
sophiabaldonado Jun 24, 2016
1387717
got rid of console.log in customers and added 2 function tests in ren…
nlcurry Jun 24, 2016
3018926
got rid of console.log
nlcurry Jun 24, 2016
54f7921
Movies Controller tests;
sophiabaldonado Jun 24, 2016
4c4c4e2
Worked on json docs;
sophiabaldonado Jun 24, 2016
0262103
Merge branch 'master' of github.com:nlcurry/VideoStoreAPI
sophiabaldonado Jun 24, 2016
562f888
adding
nlcurry Jun 24, 2016
2ce235d
merging
nlcurry Jun 24, 2016
1ab0578
Worked on docs;
sophiabaldonado Jun 24, 2016
cbfe66f
more controller tests
nlcurry Jun 24, 2016
8ad23bd
Merge branch 'master' of github.com:nlcurry/VideoStoreAPI
nlcurry 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
node_modules/
coverage/
19 changes: 16 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var massive = require('massive')

var app = express();

module.exports = app;
var connectionString = "postgres://localhost/cassettecollection_" + app.get('env')
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');
Expand All @@ -21,8 +24,19 @@ 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 Expand Up @@ -54,5 +68,4 @@ app.use(function(err, req, res, next) {
});
});


module.exports = app;
13 changes: 13 additions & 0 deletions controllers/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var docs = require('../docs.json')

var ApiController = {
docs: function(req, res, next) {
res.render('jadedocs')
},

jsonDocs: function(req, res, next) {
res.json(docs)
}
}

module.exports = ApiController
61 changes: 61 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 customer list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

sortBy: function(req, res, next) {
var type = req.params.query
var n = req.query.n
var p = req.query.p
var firstrow = n*(p-1)+1
var lastrow = n*p
Customer.sortBy([type,firstrow,lastrow],function(error, customers) {
if(error) {
var err = new Error("Error retrieving customer list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

current: function(req, res, next) {
var id = req.params.id
Rental.currentCheckedOut([id,'checked_out'], function(error, customers) {
if(error) {
var err = new Error("Error retrieving customer list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

history: function (req, res, next) {
var id = req.params.id
Rental.all([id], function(error, customers) {
if(error) {
var err = new Error("Error retrieving customer list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
}
}

module.exports = CustomersController
61 changes: 61 additions & 0 deletions controllers/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
var Movie = require("../models/movie")
var Customer = require("../models/customer")

var MoviesController = {
index: function (req, res, next) {
Movie.all(function(error, movies) {
if (error) {
var err = new Error("Error retrieving customer list:\n" + error.message)
err.status = 500
next(err)
} else {
res.json(movies)
}
})
},

sortBy: function (req, res, next) {
var type = req.params.query
var n = req.query.n
var p = req.query.p
var firstrow = n * (p - 1) + 1
var lastrow = n * p
Movie.sortBy([type, firstrow, lastrow], function (error, movies) {
if (error) {
var err = new Error("Error retrieving customer list:\n" + error.message)
err.status = 500
next(err)
} else {
res.json(movies)
}
})},

current: function (req, res, next) {
var title = req.params.movie
Customer.customersWithMovie([title], function (error, movies) {
if (error) {
var err = new Error("Error retrieving customer list:\n" + error.message)
err.status = 500
next(err)
} else {
res.json(movies)
}
})},

sortedHistory: function (req, res, next) {
var title = req.params.movie
var sort = req.params.by
Customer.rentedThisMovie([title, sort], function (error, movies) {
if (error) {
var err = new Error("Error retrieving customer list:\n" + error.message)
err.status = 500
next(err)
} else {
res.json(movies)
}
})}


}

module.exports = MoviesController
81 changes: 81 additions & 0 deletions controllers/rentals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
var Rental = require("../models/rental")
var Movie = require("../models/movie")
var Customer = require("../models/customer")

var RentalsController = {

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

Movie.rentalInfo([title], function (error, rentals) {
if(error) {
var err = new Error("Error retrieving movie info:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(rentals)
}
})},

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

Customer.currentlyCheckedOut([title],function (error, customers) {
if(error) {
var err = new Error("Error retrieving overdue list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

checkOut: function (req, res, next) {
var title = req.params.movie
var id = 55
// need to test to see if customer's id comes in body
// if we don't want to have them passed in the body we can alter the url to take a
// second parameter ->/rentals/:movie/check-out/:cust_id

Rental.checkOut([title, id],function (error, rental) {
if(error) {
var err = new Error("Error checking out rental:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(rental)
}
});
},

return: function (req, res, next) {
var title = req.params.movie
var id = 55
// need to test to see if customer's id comes in body

Rental.return([title, id],function (error, rental) {
if(error) {
var err = new Error("Error checking out rental:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(rental)
}
});
},

overdue: function (req, res, next) {
Rental.overdueList(function (error, rentals) {
if(error) {
var err = new Error("Error retrieving overdue list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(rentals)
}
});
}
}

module.exports = RentalsController
44 changes: 44 additions & 0 deletions db/seeds/rentals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[
{
"movie_id": 2,
"customer_id": 4,
"status": "checked_out",
"checkout_date": "2016-06-14",
"due_date": "2016-06-24"
},
{
"movie_id": 4,
"customer_id": 4,
"status": "returned",
"checkout_date": "1960-06-03",
"due_date": "1960-06-13"
},
{
"movie_id": 1,
"customer_id": 4,
"status": "checked_out",
"checkout_date": "2016-06-03",
"due_date": "2017-06-13"
},
{
"movie_id": 33,
"customer_id": 55,
"status": "overdue",
"checkout_date": "1960-06-03",
"due_date": "1960-06-13"
},
{
"movie_id": 1,
"customer_id": 3,
"status": "returned",
"checkout_date": "2016-06-02",
"due_date": "2016-06-12"
},
{
"movie_id": 1,
"customer_id": 4,
"status": "returned",
"checkout_date": "1960-06-03",
"due_date": "1960-06-13"
}
]
41 changes: 41 additions & 0 deletions db/setup/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
DROP TABLE IF EXISTS movies;
CREATE TABLE movies(
id serial PRIMARY KEY,
title text,
overview text,
release_date text,
inventory integer
);

CREATE INDEX movies_title ON movies (title);
CREATE INDEX movies_date ON movies (release_date);

DROP TABLE IF EXISTS customers;
CREATE TABLE customers(
id serial PRIMARY KEY,
name text,
registered_at text,
address text,
city text,
state text,
postal_code text,
phone text,
account_credit decimal
);

CREATE INDEX customers_name ON customers (name);
CREATE INDEX customers_date ON customers (registered_at);
CREATE INDEX customers_postal ON customers (postal_code);

DROP TABLE IF EXISTS rentals;
CREATE TABLE rentals(
id serial PRIMARY KEY,
movie_id integer REFERENCES movies (id),
customer_id integer REFERENCES customers (id),
status text,
checkout_date text,
due_date text
);

CREATE INDEX rentals_customers ON rentals (customer_id);
CREATE INDEX rentals_status ON rentals (status);
Empty file added db/setup/seed.sql
Empty file.
Loading