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

Yordanos & Val #7

Open
wants to merge 44 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
ac77c9d
Set up basic controller structure for customers and tested out our co…
digivava Jun 14, 2016
060d1a6
Created other controller bases and added massive as a dependency
digivava Jun 14, 2016
39bd746
Wrote some scripts for handling database, and set up connection with …
digivava Jun 14, 2016
95af556
removed load_schema file and added a seed file in tasks. Seeding data…
yordanosd Jun 15, 2016
31e6969
Set up controller for movies and movie.all method in movie model. wor…
digivava Jun 16, 2016
03945db
Made it so db.movies.run callback method creates a new instance of movie
digivava Jun 16, 2016
9e675f8
added models folder and account.js file. created a find function in t…
yordanosd Jun 16, 2016
8bfcc38
changed commit differences in app.js file
yordanosd Jun 16, 2016
4594099
fixed a missing a comma in the controller before current that was cra…
yordanosd Jun 16, 2016
74f7d14
Set up error handling for movies controller index method
digivava Jun 16, 2016
18067f2
fixing merge conflict from another branch
yordanosd Jun 16, 2016
f519cdf
movies index endpoint WORKING FOR REALS yay
digivava Jun 16, 2016
ec2b0ce
Wrote callback method for Movie.sort in moviecontroller
digivava Jun 17, 2016
58f07cd
Finished Movie.sort method in model
digivava Jun 17, 2016
424a319
Added limit and offset functionality to Movie.sort
digivava Jun 17, 2016
4ee5fa1
completed customers sort path
yordanosd Jun 17, 2016
622ea10
uncommented movie and rental routes in app file
yordanosd Jun 17, 2016
d63af90
fixed merge conflict in app file
yordanosd Jun 17, 2016
772c29e
created a script to run our test env
yordanosd Jun 17, 2016
5232b46
Created blank files for all controller tests and unit tests
digivava Jun 17, 2016
105ddba
Trying to get test script working
digivava Jun 17, 2016
2c3aa1c
Fixed WEIRD issue with npm test not working
digivava Jun 17, 2016
8e1622a
added test db connection to seed and schema file
yordanosd Jun 17, 2016
75ab1a4
added '/' route and added 'movies route' to movies controller test
yordanosd Jun 17, 2016
77fb09c
finished reseeding data for both database types
yordanosd Jun 20, 2016
3632ea9
Got rentals show URL working
digivava Jun 20, 2016
f12e2cf
Adjusted rentals show method so it gives back a single instance of a …
digivava Jun 20, 2016
46f492b
Removed id from JSON response for rentals show route
digivava Jun 20, 2016
6810c88
Removed total_inventory column and replaced with regular ol inventory…
digivava Jun 20, 2016
812608d
Added POST route for rentals/:title/check-out
digivava Jun 20, 2016
56cdff7
added the rental fee to customer and now returning both rental and cu…
yordanosd Jun 20, 2016
0f8896e
Added callback to updating customer info. The account credit now goes…
digivava Jun 21, 2016
fd96a61
Working on Movies.current functionality
digivava Jun 21, 2016
4a3ea36
Movie.current method now fully working. Changed time value for create…
digivava Jun 21, 2016
02faef6
Inventory for movie now decreases when you check a copy out
digivava Jun 21, 2016
cf79f7d
Started documentation for movies routes
digivava Jun 23, 2016
2ae54b1
Finished documentation for movie routes
digivava Jun 23, 2016
3501756
Currently working on api HTML version
digivava Jun 23, 2016
c06f642
Got HTML view set up for documentation
digivava Jun 24, 2016
ecbb4c7
Trying to format HTML view of documentation to show up in a user-read…
digivava Jun 24, 2016
35dcf4e
Added formatting for readability to HTML view
digivava Jun 24, 2016
893c08b
HTML VERSION OF DOCUMENTATION IS FINALLY DONE, I SHOULD HAVE USED REC…
digivava Jun 24, 2016
3310410
Added controller test to see if JSON is returned from json docs page
digivava Jun 24, 2016
256f4e2
Added a model test to movie model, and one controller test for rentals
digivava 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
26 changes: 22 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ 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();
var app = module.exports = express();

// database setup
var connectionString = "postgres://localhost/videostore_api_" + 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');
app.set('view engine', 'ejs');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
Expand All @@ -21,7 +27,19 @@ app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

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

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

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

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


// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
44 changes: 44 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
var Customer = require("../models/customer");

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);
}
});
},
current: function(req, res, next) {
Customer.find(req.params.id, function(error, customer) {
if(error) {
var err = new Error("No such customer");
err.status = 404;
next(err);
} else {
customer.getCurrent(function(error, current) {
res.render(current);
});
}
});
},
sort: function(req, res, next) {
var options = {order: req.params.search, limit: req.query.n, offset: req.query.p}
Customer.sort(options, 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;
22 changes: 22 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var docs = require('../docs.json');

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

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

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

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

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


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

},

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

current: function(req, res, next) {
Movie.current(req.params.title, function (error, result) {
if (error) {
var err = new Error("Error retrieving movies:\n" + error.message);
err.status = 500;
next(err);
} else {
// if (result.length === 0) {
// res.status(204); //not working for some reason, fix later
// }
res.json(result);
}
});
}

};

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

var RentalsController = {
show: function(req, res, next) {
Rental.findTitle(req.params.title, function(error, movie) {
if(error) {
var err = new Error("No such movie title");
err.status = 404;
next(err);
} else {
delete movie.id;
res.json(movie);
};
});
},

checkOut: function(req, res, next) {
var customer_id = req.body.customer_id;
var title = req.params.title;
Rental.createCheckOut(customer_id, title, function(error, rental) {
if(error) {
var err = new Error("Rental checkout failed");
err.status = 404;
next(err);
} else {
res.json(rental);
}
});
}
};


module.exports = RentalsController;
1 change: 1 addition & 0 deletions coverage/coverage.json

Large diffs are not rendered by default.

Loading