Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
b10191e
Wrote pseudocode for routes.
jadevance Jun 14, 2016
7e69068
Added in Massive
jadevance Jun 14, 2016
f80ff64
added db and db/setup dirs, added scripts for setups in the package.j…
JBoshart Jun 14, 2016
fe3633f
omg it works
jadevance Jun 14, 2016
3f994c9
added high level routes for customers, movies and rentals
jadevance Jun 15, 2016
bbec298
Added tasks folder with load schema functionality
jadevance Jun 15, 2016
448164b
Pushing broken code so we can work on it tonight: Most of the work do…
JBoshart Jun 15, 2016
a46f4b2
Changed some things?
jadevance Jun 16, 2016
e0611b6
merge conflicts
jadevance Jun 16, 2016
bb8ed63
Seed.js is now working.
JBoshart Jun 16, 2016
df311ed
Added schema for rentals database.
JBoshart Jun 16, 2016
cf69655
Added ERD to git.
JBoshart Jun 16, 2016
9aa4d2b
added setup for the database in app.js
jadevance Jun 16, 2016
e929b92
added a models folder as well as model function to find all customers
jadevance Jun 16, 2016
cc7ebf3
wrote a method in the video controller to find all customers in the d…
jadevance Jun 16, 2016
de5b757
forgot to reference the model in the controller. Fixed that. Renamed …
jadevance Jun 16, 2016
944c7a9
resolved merge conflict.
JBoshart Jun 16, 2016
38d4c13
Added module.exports to app
jadevance Jun 16, 2016
e4ff73c
required massive and cleaned up errors
jadevance Jun 16, 2016
22e7117
Fixed a syntax error that broke everything
jadevance Jun 17, 2016
fca5fdd
Switching drivers. Working on getting JSON response.
JBoshart Jun 17, 2016
4117137
endpoint customers is now serving up customer data in JSON
jadevance Jun 17, 2016
1dc233a
renamed video.js to customers.js to split out the functionality of cu…
jadevance Jun 17, 2016
a1f4b7f
Organizational changes only.
JBoshart Jun 17, 2016
7e73318
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 17, 2016
22c9cc3
More org changes.
JBoshart Jun 17, 2016
e704d83
Added functionality for sorting customers
jadevance Jun 17, 2016
59ed614
managing merge conflicts
jadevance Jun 17, 2016
dd0eabe
Customers can be sorted now and the return is JSON data. yay
jadevance Jun 17, 2016
dc60de7
Set h1 for funsies.
JBoshart Jun 17, 2016
3ff63c7
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 17, 2016
ef395bf
Made models and controllers for rentals and videos.
JBoshart Jun 17, 2016
dacb023
added seed data for rentals database, and adjusted seeding code.
JBoshart Jun 17, 2016
2b4eeda
broke out routes for clarity (and because express had callback issues…
jadevance Jun 17, 2016
b259277
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
jadevance Jun 17, 2016
65ab567
work in rentals model and controller.
JBoshart Jun 17, 2016
e18f050
fixed routing where it was nested one level too deep (/customers/cust…
jadevance Jun 17, 2016
75164a2
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
jadevance Jun 17, 2016
ef2faa5
Working on Rentals.find in controller.
JBoshart Jun 17, 2016
3c56b1f
routes
jadevance Jun 17, 2016
a2faf4f
still. with. rentals. find. :(
JBoshart Jun 17, 2016
8ca4618
merge conflicts manages in app.js and rentals controller
jadevance Jun 17, 2016
b87aea8
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
jadevance Jun 17, 2016
2970cb0
Completed the find_current rentals funciton in model and contorller. …
JBoshart Jun 17, 2016
e41e909
friday changes, honestly do not remember what was changed
jadevance Jun 20, 2016
8a017c0
added istanbul and managed a merge conflict with rentals routes
jadevance Jun 20, 2016
f74c963
Added more seed data inorder to test sorting function of rentals hist…
JBoshart Jun 20, 2016
4da9636
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 20, 2016
37ab377
Added null seeds for checkin and modified the models sql query to ret…
jadevance Jun 20, 2016
0241bc0
Added coverage to the gitignore file
jadevance Jun 20, 2016
c80b182
resolving errors that occured when coverage/ was not in our git ignore.
JBoshart Jun 20, 2016
c7c524c
Trying to resolved merge
JBoshart Jun 20, 2016
4162e25
Added node modules to the .gitignore
jadevance Jun 20, 2016
23a8b4d
video_current now returns the customers who currently have a particul…
JBoshart Jun 20, 2016
ee69dd8
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 20, 2016
3ae103b
Wrote a function, route and model method for finding the rental histo…
jadevance Jun 20, 2016
857b62b
Wrote functionality for funding a list of customers who have currentl…
jadevance Jun 20, 2016
f450b9b
Worked on adding checkout functionality to our video store. Routing n…
jadevance Jun 21, 2016
fd2f0c5
debugging code, have the first two pieces of checkout working but the…
jadevance Jun 21, 2016
61d640f
Created a constructor function to test checkout rentals
jadevance Jun 21, 2016
a155863
Fixed date and time
jadevance Jun 21, 2016
de7a513
Worked on rentals checkin function.
JBoshart Jun 21, 2016
7221273
Debugging work on checking process.
JBoshart Jun 21, 2016
85797a9
Checkin function is now working
JBoshart Jun 21, 2016
1a25dd2
Fixed error handling to display json rather than render a view for er…
jadevance Jun 21, 2016
34aa7a5
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
jadevance Jun 21, 2016
76fcb75
Wrote error handling for customers, cleaned up unused code
jadevance Jun 21, 2016
b5cb520
added video error handling
jadevance Jun 21, 2016
1fcd557
Working on overdue rentals.
JBoshart Jun 21, 2016
9fc2fc3
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 21, 2016
b715f0f
Wrote tests for the videos controller (renamed from movies for clarit…
jadevance Jun 22, 2016
92a93db
Added tests for customers controller.
jadevance Jun 22, 2016
070171c
Wrote some tests for the rentals controller
jadevance Jun 22, 2016
d537234
Merging tests with local
JBoshart Jun 22, 2016
72dfb1b
overdue function for rentals is now working.
JBoshart Jun 22, 2016
21fc575
Added model specs and cleaned up error responses in the controllers
jadevance Jun 22, 2016
33fe746
Made rentals#overdue tests, as well as model spec directory.
JBoshart Jun 22, 2016
cf20434
isolated the failing test and it is currently x and commented out in …
jadevance Jun 22, 2016
45c0130
Managing merge conflicts, commented out tests that do not currently work
jadevance Jun 23, 2016
33e1b27
Fixed failing test, endpoint had a typo
jadevance Jun 23, 2016
c5bc420
writing model tests for customers
jadevance Jun 23, 2016
b08e506
Added in package.json command to clean up test coverage reports
jadevance Jun 23, 2016
f54b3b2
Added new testing command to package.json.
JBoshart Jun 23, 2016
db2982b
Added tests to the rental models spec for find_current and find_history.
JBoshart Jun 23, 2016
6995b8f
Added tests to rentals model spec for .overdue.
JBoshart Jun 23, 2016
d08365a
Added tests to rentals model spec for .video_current.
JBoshart Jun 23, 2016
3ae0f78
Added tests to rentals model spec for .video_current, more will need …
JBoshart Jun 23, 2016
83e3f06
Wrote a sorting function for rentals to return JSON data sorted by name
jadevance Jun 23, 2016
345ad66
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 23, 2016
d451759
added notes to remind us to address checkout date
jadevance Jun 23, 2016
c0506d2
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
jadevance Jun 23, 2016
9b7606e
Handled checkout date logic for sorting
jadevance Jun 23, 2016
d55204e
More tests in progress.
JBoshart Jun 23, 2016
9f7da07
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart Jun 23, 2016
d808692
Sorting tests for find_video_history
JBoshart Jun 23, 2016
dd5593c
Wrote tests for video model. I think we should write some tests for .…
JBoshart Jun 23, 2016
4f0e70e
error handling tests for models controllers is now in place and at 91…
JBoshart Jun 24, 2016
dfdf543
customers spec is now testing at 94% coverage.
JBoshart Jun 24, 2016
a373466
wrote tests for rentals to handle error handling
jadevance Jun 24, 2016
fae25cf
cleaning up the files
jadevance Jun 24, 2016
34d7557
Removed views that were not being used. Added Api Documentation.
JBoshart Jun 24, 2016
ceba217
Merge branch 'master' of github.com:JBoshart/VideoStoreAPI
JBoshart 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/
Binary file added ERD.pdf
Binary file not shown.
34 changes: 28 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,47 @@ 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/extreme_video_express";
var db = massive.connectSync({connectionString: connectionString});
app.set('db', db);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so jealous. This project would've helped me so much in my capstone. It took me 2 days to figure out how to set up a database and then connect with it from within my (non rails) app. So yay! This concept is really important :)


// 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')));

app.use(logger('dev'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging is also really important!

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
//
// routes
//

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

//
// error handlers
//

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand All @@ -30,14 +53,13 @@ app.use(function(req, res, next) {
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', {
res.json('error', {
message: err.message,
error: err
});
Expand Down
34 changes: 34 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var Customers = require("../models/customers");

var CustomersController = {

getCustomers: function (request, response, next) {
Customers.all(function(error, customers) {
if(error) {
var err = new Error
err.status = 500;
err.error = "Error retrieving customer list."
response.json(err)
} else {
response.json(customers)
}
});
},

// customer id, sort column, offset (p and n)
getCustomersSorted: function(request, response) {
Copy link

@noglows noglows Jun 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've noticed on this method you didn't include next as a param but you do so in a lot of the other controller methods. I would recommend being consistent on whether or not you include it. (Caveat: I am not super familiar with Express and there may be a totally legitimate reason you did this :) )

Customers.sort(request.params.column, request.query.p, request.query.n, function(error, customers) {
if(error) {
var err = new Error
err.status = 404;
err.error = "Not found :("
response.json(err)
} else {
response.json(customers)
}

})
},
}

module.exports = CustomersController;
16 changes: 16 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var IndexController = {
// Baseline project requirement, left for completion purposes:
// getZomg: function (request, response) {
// var locals = {};
// locals.zomg = JSON.stringify('It Works!!!!!');
// response.render('index', locals);
// },

getApiDocs: function (request, response) {
var locals = {}
locals.weneedthisiguess = JSON.stringify()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is weneedthisiguess?

response.render('index', locals)
}
}

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

var RentalsController = {

getCurrentRentals: function (request, response, next) {
Rentals.find_current(request.params.customer_id, function(error, rentals) {
if(error) {
var err = new Error
err.status = 500;
err.error = "Error retrieving customer's current rentals."
response.json(err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay error handling!

} else {
response.json(rentals)
}
});
},

getRentalHistory: function (request, response, next) {
Rentals.find_history(request.params.customer_id, function(error, rentals) {
if(error) {
var err = new Error
err.status = 500;
err.error = "Error retrieving customer's rental history."
response.json(err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider factoring out the error handling logic, since there's a lot of repetition

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A neat way to handle what @hougland is suggesting is creating an error middleware. See: https://derickbailey.com/2014/09/06/proper-error-handling-in-expressjs-route-handlers/ for an example

} else {
response.json(rentals)
}
});
},

getVideoCurrent: function(request, response, next) {
Rentals.video_current(request.params.title, function(error, rentals) {
if(error) {
var err = new Error
err.status = 500;
err.error = "Error retrieving video rentals list."
response.json(err)
} else {
response.json(rentals)
}
});
},

getVideoHistory: function(request, response, next) {
Rentals.find_video_history(request.params.title, request.params.ordered_by, function(error, rentals) {
if(error) {
var err = new Error
err.status = 500;
err.error = "Error retrieving video rentals list."
response.json(err)
} else {
response.json(rentals)
}
})
},

postCheckout: function(request, response, next) {
Rentals.checkout(request.params.title, request.params.customer_id, function(error, rentals) {
if(error) {
var err = new Error
err.status = 304;
err.error = "That video is not available for checkout"
response.json(err)
} else {
response.json(rentals)
}
})
},

postCheckin: function(request, response, next) {
Rentals.checkin(request.params.title, request.params.customer_id, function(error, rentals) {
if(error) {
var err = new Error
err.status = 304;
err.error = "That video is not available for return"
response.json(err)
} else {
response.json(rentals)
}
})
},

getOverdue: function(request, response, next) {
Rentals.overdue(function(error, overdue_videos) {
if(error) {
var err = new Error
err.status = 404;
err.error = "Not Found :("
response.json(err)
} else {
response.json(overdue_videos)
}
})
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these all look nice and clean, though keep an eye on indentation

module.exports = RentalsController;
60 changes: 60 additions & 0 deletions controllers/videos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var Videos = require("../models/videos");

var VideosController = {

getVideos: function (request, response, next) {
Videos.all(function(error, videos) {
if(error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job incorporating error handling into all your controller methods!

var err = new Error
err.status = 500;
err.error = "Error retrieving video rentals list."
response.json(err)
} else {
response.json(videos)
}
});
},

// video id, sort column, offset (p and n)
getVideosSorted: function(request, response) {
Videos.sort(request.params.column, request.query.p, request.query.n, function(error, videos) {
if(error) {
var err = new Error
err.status = 404;
err.error = "Not found :("
response.json(err)
} else {
response.json(videos)
}

})
},

getVideo: function (request, response) {
Videos.find(request.params.title, function(error, video) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you only expecting a single video for this method? If so, should it be a FindOne method?

if(error) {
var err = new Error
err.status = 404;
err.error = "Not found :("
response.json(err)
} else {
response.json(video)
}
})
},

getVideosByCustomer: function (request, response) {
Videos.customer_current(request.params.title, function(error, customers) {
if(error) {
var err = new Error
err.status = 404;
err.error = "Not found :("
response.json(err)
} else {
response.json(customers)
}
});
}
}

module.exports = VideosController;
67 changes: 67 additions & 0 deletions db/seeds/rentals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[
{
"customer_id": "1",
"video_id": "1",
"checkout_date": "Tues, 5 May 2015 07:54:14 -0700",
"due_date": "Wed, 6 May 2015 07:54:14 -0700",
"checkin_date": "Thu, 7 May 2015 07:54:14 -0700",
"charge": 1.50
},
{
"customer_id": "2",
"video_id": "3",
"checkout_date": "Fri, 8 May 2015 07:54:14 -0700",
"due_date": "Wed, 9 May 2015 07:54:14 -0700",
"checkin_date": null,
"charge": 1.50
},
{
"customer_id": "3",
"video_id": "1",
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700",
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700",
"checkin_date": "Fri, 1 May 2015 07:54:14 -0700",
"charge": 1.50
},
{
"customer_id": "4",
"video_id": "1",
"checkout_date": "Sat, 2 May 2015 07:54:14 -0700",
"due_date": "Sun, 3 May 2015 07:54:14 -0700",
"checkin_date": "Mon, 4 May 2015 07:54:14 -0700",
"charge": 1.50
},
{
"customer_id": "5",
"video_id": "2",
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700",
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700",
"checkin_date": "Fri, 1 May 2015 07:54:14 -0700",
"charge": 1.50
},
{
"customer_id": "6",
"video_id": "3",
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700",
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700",
"checkin_date": "Fri, 1 May 2015 07:54:14 -0700",
"charge": 1.50
},
{
"customer_id": "7",
"video_id": "6",
"checkout_date": "Wed, 22 Apr 2015 07:54:14 -0700",
"due_date": "Thu, 23 Apr 2015 07:54:14 -0700",
"checkin_date": null,
"charge": 1.50
},
{
"customer_id": "8",
"video_id": "1",
"checkout_date": "Wed, 29 Apr 2015 07:54:14 -0700",
"due_date": "Thu, 30 Apr 2015 07:54:14 -0700",
"checkin_date": null,
"charge": 1.50
}

]
Loading