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

yo #11

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

yo #11

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9d587a7
created a route, controller and view for index
mcarson1111 Jun 14, 2016
41068be
Created a route that responds to /zomg that serves a json-encoded method
mcarson1111 Jun 14, 2016
dc781ef
added a tasks folder with a load_schema.. that currently doesn't load…
Jun 14, 2016
c072b52
added pseudo routes
mcarson1111 Jun 14, 2016
8995ae3
did some changes to the schema files
mcarson1111 Jun 15, 2016
ee3e937
changes words on schema file
mcarson1111 Jun 15, 2016
46e74c3
following jeremy in class for seeding data
Jun 16, 2016
f30975b
fixed the routes and added a function and callback for Movies.all
Jun 16, 2016
ed72207
added customers and movies controller and models
Jun 17, 2016
514d424
added sequel statements to the customer and movie models instead of l…
Jun 17, 2016
4afa5e1
tried fixing the queries for all rentals and specific rentals info
mcarson1111 Jun 20, 2016
25d532b
kept both seed files
mcarson1111 Jun 20, 2016
93dc7d9
successfully created a testing and development environment. db:reset …
Jun 20, 2016
671c213
previously also created a setup.js and added istanbul for testing. ju…
Jun 20, 2016
8b71202
cleaned up conflicts from creating 2 diff env databases.
Jun 20, 2016
4856dbf
reseeded to add a searchable title column and an inventory total. fix…
Jun 20, 2016
9c7f09a
finished rentals checkout
Jun 21, 2016
12791c9
got functions for seraching movie titles and searching for customers …
mcarson1111 Jun 21, 2016
c80540d
got functions for seraching movie titles and searching for customers …
mcarson1111 Jun 21, 2016
a4dabad
added return functionality. it works
Jun 21, 2016
53fb652
updated the find customers name function to show name instead of id
mcarson1111 Jun 21, 2016
b7da68f
finished return
Jun 22, 2016
087ad12
changes were in rentals model and controller. commented out conflicti…
Jun 22, 2016
a9df2f6
sending over rental model changes
Jun 22, 2016
c0ec829
tried to finish overdue. turns out it was a problem with the order of…
Jun 22, 2016
0fdb38a
can find overdue rentals. had to split it up to be able to do time lo…
Jun 23, 2016
c61f37c
added html view of api documentation
mcarson1111 Jun 24, 2016
3fc3ce8
added instructions for customer_id sent through JSON body
mcarson1111 Jun 24, 2016
4944f85
finished overdue functionality for rentals
Jun 24, 2016
33cab26
Merge branch 'master' of github.com:mcarson1111/VideoStoreAPI
Jun 24, 2016
300cb04
finished json api documentation
mcarson1111 Jun 24, 2016
f71636a
Merge branch 'master' of github.com:mcarson1111/VideoStoreAPI
mcarson1111 Jun 24, 2016
8e796ef
added controller tests for customers, movie and rentals
Jun 24, 2016
3c9c0cc
Merge branch 'master' of github.com:mcarson1111/VideoStoreAPI
Jun 24, 2016
4ccb782
finished model testings for customers
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
Binary file added .DS_Store
Binary file not shown.
32 changes: 30 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
.DS_Store
node_modules/
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Debug log from npm
npm-debug.log
33 changes: 25 additions & 8 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,44 @@ var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var app = express();

var routes = require('./routes/index');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

var app = express();
var massive = require("massive")
var connectionString = "postgres://localhost/radio_star_" + app.get('env');


// connect to Massive and get the db instance. You can safely use the
// convenience sync method here because its on app load
// you can also use loadSync - it's an alias
var db = massive.connectSync({connectionString : connectionString});
// console.log(db)
// var db = massive.connectSync({db : "radio_star"})

// Set a reference to the massive instance on Express' app:
app.set("db", db);

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

module.exports = app;

var routes = require('./routes/index');
var users = require('./routes/users');
// var rentals = require('./routes/rentals');

// 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('/', routes);
app.use('/users', users);
// app.use('/rentals', rentals)

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down Expand Up @@ -53,6 +73,3 @@ app.use(function(err, req, res, next) {
error: {}
});
});


module.exports = app;
2 changes: 1 addition & 1 deletion bin/www
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

var app = require('../app');
var debug = require('debug')('video-store-api:server');
var debug = require('debug')('js-bank-accounts:server');
var http = require('http');

/**
Expand Down
58 changes: 58 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var Cust = require("../models/customer");

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

subset: function(req, res, next) {
// console.log(req.query)
// console.log("req params query: ", req.params.query)
Cust.sort(req.params.query, req.query.n , req.query.p, function(error, custs) {
// var n = req.params.n
// var p = req.params.p
if(error) {
var err = new Error("Error retrieving customer list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(custs)
}
});
},

// /customers/:id/current
current: function(req, res, next) {
Cust.find([req.params.id, 'true'], function(error, rentals) {
if(error) {
var err = new Error("Error retrieving customer's current movie list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(rentals)
}
});
},

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

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


var Controller = {
locals: {
documentation: docs
},

index: function(req, res, next) {
res.json('It works!!');
},

docsHTML: function(req, res, next) {
res.render('docs', Controller.locals);
},

docsJSON: function(req, res, next) {
res.json(200, docs);
}
};

module.exports = Controller;



// var HomePage = {
// zomg: function(req,response) {
// var hi= {"hi": "ZOMG"}
// response.json({cow: 'ZOMG!'})
// },
//
// nothing: function(req, response) {
// response.render('index', {title: 'Express'});
// }
// };
//
// module.exports = HomePage;
91 changes: 91 additions & 0 deletions controllers/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
var Movie = require("../models/movie");

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

find: function(req, res, next) {
Movie.sort(req.params.query, req.query.n , req.query.p, function(error, movies) {
if(error) {
var err = new Error("Error retrieving movies list:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(movies)
}
});
},

// /movies/:movie/current
current: function(req, res, next) {
var movie = req.params.movie
var movie = movie.toLowerCase().replace(/^./, movie[0].toUpperCase());
Movie.find(['true', movie], 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)
}
});
},

history: function(req, res, next) {
var movie = req.params.movie
var movie = movie.toLowerCase().replace(/^./, movie[0].toUpperCase());

console.log(req.params.query)
Movie.history(['false', movie], req.params.query, 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)
}
});
}

// subset: function(req, res, next) {
// Movie.subs(function(error, movies) {
// var n = req.params.n
// var p = req.params.p
// if(error) {
// var err = new Error("Error retrieving movies list:\n" + error.message);
// err.status = 500;
// next(err);
// } else {
// res.json(movies)
// }
// });


// Retrieve a subset of movies (/movies/sort/release-date?n=5&p=1)
// Given a sort column, return n movie records, offset by p records (this will be used to create "pages" of movies)
// Sort columns are
// title
// release_date

// sort: function(req, res, next) {
// Movie.sort(function(error, movies) {
// if(error) {
// var err = new Error("Error retrieving movie info:\n" + error.message);
// err.status = 500;
// next(err);
// } else {
// res.json(movies)
// }
// })
// }
}
module.exports = MovieController;
74 changes: 74 additions & 0 deletions controllers/rentals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var Rental = require('../models/rental');

var RentalsController = {
// /rentals/:movie
// returns overview, release_date available inventory and total inventory
find: function(req, res, next) {
Rental.search([req.params.movie.toLowerCase().replace(/ /g, "").replace(/\./g, "")], function(error, movie) {
if(error) {
var err = new Error("Error retrieving movie:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(movie)
}
});
},

findCustomers: function(req, res, next) {
Rental.searchCust(['true', req.params.movie.toLowerCase().replace(/ /g, "").replace(/\./g, "")], function(error, customers) {
if(error) {
var err = new Error("Error:" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

checkOut: function(req, res, next) {
// Rental.checkout([req.body.customer], [req.params.movie.toLowerCase().replace(/ /g, "").replace(/\./g, "")], function(error, customers) {
console.log(req.params.id)
Rental.checkout([req.params.id], [req.params.movie.toLowerCase().replace(/ /g, "").replace(/\./g, "")], function(error, customers) {
if(error) {
var err = new Error("Error, could not check out movie at this time:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

return: function(req, res, next) {
// Rental.return([req.body.customer], [req.params.movie.toLowerCase().replace(/ /g, "").replace(/\./g, "")], function(error, customers) {
Rental.return([req.params.id], [req.params.movie.toLowerCase().replace(/ /g, "").replace(/\./g, "")], function(error, customers) {
if(error) {
var err = new Error("Error, could not return movie at this time:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(customers)
}
});
},

// See a list of customers with overdue movies (/rentals/overdue)
// include customer name, movie title, check-out date, and return date
overdue: function(req, res, next) {
Rental.overdue(Date.now(), function(error, overdueInfo) {
if(error) {
var err = new Error("Error could not retrieve customers:\n" + error.message);
err.status = 500;
next(err);
} else {
res.json(overdueInfo)
}
});
}

};


module.exports = RentalsController;
23 changes: 23 additions & 0 deletions db/seeds/rentals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[
{
"movie_id": "1",
"customer_id": "1",
"checked": "false",
"rental_date": "Wed, 29 Apr 2015 07:54:14 -0700",
"due_date": "Wed, 06 May 2015 07:54:14 -0700"
},
{
"movie_id": "2",
"customer_id": "1",
"checked": "true",
"rental_date": "Fri, Jun 17 2016 13:33:34 -0700",
"due_date": "Fri, Jun 24 2016 13:33:34 -0700"
},
{
"movie_id": "3",
"customer_id": "1",
"checked": "true",
"rental_date": "Fri, Jun 17 2016 13:33:34 -0700",
"due_date": "Fri, Jun 24 2016 13:33:34 -0700"
}
]
Loading