Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
1f9bb09
added customers and movies route files
annamm77 Jun 14, 2016
e3ccafe
added movies and customers routes to app.js
annamm77 Jun 14, 2016
86d8707
moved something
annamm77 Jun 14, 2016
3aac48f
tested zomg route and it worked
annamm77 Jun 14, 2016
2d87356
Added massive to npm, and gave it wave1 scripts
nicosaki Jun 14, 2016
3125a51
single route change /sort
nicosaki Jun 14, 2016
085fa3d
db/setup schema
nicosaki Jun 14, 2016
6289482
load schema and (non functional) seeding tasks
nicosaki Jun 14, 2016
4b9a5c9
Updated package.json; scripts + seed to db:reset (not yet working)
nicosaki Jun 14, 2016
44cf9d1
Added instance of controller to customers routes
nicosaki Jun 14, 2016
80cc378
Added instance of movies to movies routes
nicosaki Jun 14, 2016
92c4acf
extra index routes
nicosaki Jun 14, 2016
c13105c
fixed scripts, seed still bad
nicosaki Jun 14, 2016
82528b9
Idunnolol
nicosaki Jun 14, 2016
d064cb3
Controller scaffolding, no complete methods
nicosaki Jun 14, 2016
9e4f462
Customers routes updated
nicosaki Jun 14, 2016
4334276
task to seed - INCORRECT
nicosaki Jun 14, 2016
aeaad3c
movies routes to controller, includes rentals
nicosaki Jun 14, 2016
8b82b56
not sure what you want me to commit, git
nicosaki Jun 14, 2016
ea9ab9b
log stuff that probably goes in the .gitignore
nicosaki Jun 14, 2016
740a680
moved controllers to correct file, deleted extra movies controller
annamm77 Jun 15, 2016
d967453
updated seed script, unknown if works
nicosaki Jun 15, 2016
d0f5940
finished seed script with asynch functionality
nicosaki Jun 15, 2016
e1b1b14
fixed schema - still no index but is working
nicosaki Jun 15, 2016
e0bfbbc
fixed massive db errors
nicosaki Jun 15, 2016
273fb94
edited an error where massive was being referred to as a database. ch…
annamm77 Jun 15, 2016
3399dab
fixed seed script
nicosaki Jun 15, 2016
7ce6835
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 15, 2016
0d437a2
two SQL commands for movies controller
annamm77 Jun 16, 2016
c51dd94
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 16, 2016
f100322
sorttitle controller function returns JSON of sorted movie titles
annamm77 Jun 16, 2016
ea0a928
movies sortrelease works
annamm77 Jun 16, 2016
b254141
created rentals seed
annamm77 Jun 16, 2016
c445524
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 16, 2016
730fd1c
Added rental seed script
nicosaki Jun 16, 2016
28c1ac3
Ability to see currently checked out movies by id number
nicosaki Jun 16, 2016
b1a410f
Ability to see previously checked out movies by id number
nicosaki Jun 16, 2016
0abe12d
added rentals to app.js routes
annamm77 Jun 16, 2016
444e42a
no rentals routes nevermind hehe
annamm77 Jun 16, 2016
8b5b222
Added all movies endpoints and rentalsTitle(NONFUNCTIONAL) to movies …
nicosaki Jun 16, 2016
58900ea
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 16, 2016
f8acce5
added customer id to movie routes that check in and check out movies
annamm77 Jun 16, 2016
465c269
scaffolded return function
annamm77 Jun 16, 2016
378b6b3
updated movies/rentals/return route to a get
annamm77 Jun 17, 2016
05362cf
return function does what it's supposed to. might want to change what…
annamm77 Jun 17, 2016
4359739
return route returns 200 success upon update
annamm77 Jun 17, 2016
24d49ec
changed movies/returns/checkout to get
annamm77 Jun 17, 2016
362f029
checkout function will create a new rental instance
annamm77 Jun 17, 2016
49d5632
Methods all complete and functional for customer routes
nicosaki Jun 17, 2016
5ab6d98
All methods added for movie routes, functional, wheee
nicosaki Jun 17, 2016
c372c91
All endpoints complete and functional
nicosaki Jun 17, 2016
172a544
added movies / route
annamm77 Jun 17, 2016
8efb962
added allMovies controller function for / path
annamm77 Jun 17, 2016
3faea59
moved rentals/overdue route above rentals/:id route because it was ge…
annamm77 Jun 17, 2016
09714e0
overdue controller function works
annamm77 Jun 17, 2016
4ea9647
Fixed customer info show for current and history sorts
nicosaki Jun 17, 2016
08c4f34
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 17, 2016
def6b6f
added start-test and test scripts
annamm77 Jun 17, 2016
4de6aee
added customers controller spec file
annamm77 Jun 17, 2016
da60deb
added n and p to queries involving configurable sorting
nicosaki Jun 17, 2016
78d72af
movies controller with custome information displayed in current/histo…
nicosaki Jun 17, 2016
644b1db
fixed route for sorting by release-date
nicosaki Jun 17, 2016
457d37c
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 17, 2016
a60b62f
all endpoints complete and functionally tested. Formal testing next
nicosaki Jun 17, 2016
e5f18d0
checkout function deducts from customers account
annamm77 Jun 20, 2016
e0b5145
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
annamm77 Jun 20, 2016
8e7ff34
checkout and return are now posts instead of gets. works in postman s…
annamm77 Jun 20, 2016
43b7613
installed istanbul
annamm77 Jun 20, 2016
50e9829
remove coverage from git tracking
annamm77 Jun 20, 2016
0cd3c08
updated test script to include instanbul and it works yey
annamm77 Jun 20, 2016
57a09ab
Created documentation for our API, have not yet connected its existen…
nicosaki Jun 20, 2016
775ae32
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 20, 2016
9aee2be
tests for /movies route
annamm77 Jun 20, 2016
aa195e6
testing for /customers
annamm77 Jun 20, 2016
4a3e3aa
Added .json documentation endpoint, successful.
nicosaki Jun 20, 2016
1044e71
Merge branch 'master' of github.com:annamw77/VideoStoreAPI
nicosaki Jun 20, 2016
3e8b816
added array of objects tests for movies and cusomters
annamm77 Jun 21, 2016
8dc8e1e
Minor test change
nicosaki Jun 21, 2016
e9121ec
test coverage for more endpoints in movies
annamm77 Jun 21, 2016
8a34e0d
fixmerge
nicosaki Jun 22, 2016
5b5a978
MERGE ALREADY
nicosaki Jun 22, 2016
d21395e
Fixed tests, all pass; functional testing not being checked by istanbul
nicosaki Jun 23, 2016
8d89d2c
deleted a bracket because javascript
annamm77 Jun 23, 2016
5169923
removed the bracket i worked so hard to delete
annamm77 Jun 23, 2016
3370f6b
refactored doubled sql commands
annamm77 Jun 23, 2016
226ab50
added details for checkout route
annamm77 Jun 24, 2016
6b1acb1
fixed bug with rentalstitle
annamm77 Jun 24, 2016
8cd23ac
edited checkout URL
annamm77 Jun 24, 2016
93668cc
added statement about errors
annamm77 Jun 24, 2016
3158e46
edited some so that errors will show
annamm77 Jun 24, 2016
439fb49
minor edits
annamm77 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
138 changes: 60 additions & 78 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,100 +1,82 @@
# Project: VideoStoreAPI
The overall goal of this project is to create a system that a video store (remember those?) could use to track their inventory of rental videos and their collection of customers.
- All endpoints return JSON data unless explicitly stated otherwise. If there is no data/record to return a message such as "This movie has not yet been checked out" or "This customer has not yet checked out a movie" will be returned.

We will use [NodeJS](https://nodejs.org/en/) and [Express](http://expressjs.com/) to construct a RESTful API. The goal of this API is to quickly serve information about the store's video collection, customer information, and to update rental status. This repository provides two JSON datafiles to serve as the initial seeds for this system.

## Project Baseline
- Read the API Requirements below and create a pseudo-code "routes" file that
- defines the _endpoints_ your API will need
- the _HTTP verbs_ each endpoint will use
- and any data that must be provided to the endpoint in order for it to do its work.
- Create a new Node/Express app to serve as the API.
- Create a route that responds to `/zomg` that serves a json-encoded "it works!" method.

## Wave 1: Database Models, Tables, & Seeds
- Create an ERD for your database by reading through all of the requirements below.
- Be sure your ERD includes primary keys for all tables
- Leverage MassiveJS and create custom npm scripts to...
- create a development database
- drop a development database
- apply a schema to the database
- seed a database using the provided json data in `db/seeds`

### Seed Data
`movies.json` contains information about the videos available to rent at the store. The data is presented as an array of objects, with each object having the following key-value pairs:

- `title`: The title of the film
- `overview`: A short plot synopsis
- `release_date`: When the film was originally released
- `inventory`: How many copies of the film the video store owns

`customers.json` contains information about the customers that have rented with the store in the past. The data is presented as, you guessed it, an array of objects, with each object have the following key-value pairs:

- `name`: The customer's name
- `registered_at`: When the customer first visited the store
- The customer's physical address, composed of:
- `address`
- `city`
- `state`
- `postal_code`
- `phone`: Primary contact phone number
- `account_credit`: For reason we'd rather not get into, the store owes all of their customers a little bit of money; this amount is made available to customers as credit toward future rentals.

## Wave 2: API Requirements
The API you build should have the following capabilities. The schema of your database and the structure of the endpoints are completely up to you. Make every effort to conform to RESTful routing patterns. Every endpoint (except for `/zomg` from the baseline) must serve `json` data. Use HTTP response codes to indicate the status of the request.

#### Authentication
- There is not an authentication requirement for this project; assume all users interacting with the API are video store employees.

#### Interface
- This part of the project is purely an API; all interactions should happen over HTTP requests. There is no front-end, user-facing interface.
- All endpoints are assumed to be GET unless explicitly stated otherwise

#### Customers
- Retrive a list of all customers (`/customers`)
- Retrive a subset of customers (`/customers/sort/name?n=10&p=2`)
- Retrive a list of all customers: (`/customers`)
- Retrive a subset of customers (`/customers/sort/:sort_params`)
- Given a sort column, return _n_ customer records, offset by _p_ records (this will be used to create "pages" of customers)
- Sort columns are
- `name`
- `registered_at`
- `postal_code`
- Sort params are
- `name` : (`/name?n=10&p=2`)
- `registered_at` example: (`/registered-at?n=10&p=2`)
- `postal_code` example: (`/postal-code?n=10&p=2`)
- Given a customer's `id`...
- List the movies they _currently_ have checked out (`/customers/5/current`)
- List the movies a customer has checked out in the past (`/customers/5/history`)
- List the movies they _currently_ have checked out (`/customers/:customer_id/current`)
- List the movies a customer has checked out in the past (`/customers/:customer_id/history`)
- ordered by check out date
- includes return date

#### Movies
- Retrieve a list of all movies (`/movies`)
- Retrieve a subset of movies (`/movies/sort/release-date?n=5&p=1`)
- Retrieve a subset of movies (`/movies/sort/:sort_params`)
- 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`
- Given a movie's `title`...
- Get a list of customers that have _currently_ checked out a copy of the film (`/movies/Jaws/current`)
- include each customer's name, phone number, and account credit
- Get a list of customers that have checked out a copy _in the past_ (`/movies/Jaws/history/sort/name`)
- include each customer's name, phone number, and account credit
- ordered by customer `name` __or__
- ordered by check out date
- Sort params are
- `title` example: (`/title?n=5&p=1`)
- `release_date` example: (`/release-date?n=5&p=1`)
- Given a movie's `id`...
- Get a list of customers that have _currently_ checked out a copy of the film (`/movies/:movie_id/current`)
- includes each customer's name, phone number, and account credit
- Get a list of customers that have checked out a copy _in the past_
- includes each customer's name, phone number, and account credit
- ordered by customer `name` (`/movies/:movie_id/history/sort/name`)
- ordered by `check-out` (`/movies/:movie_id/history/sort/date`)

#### Rental
- Look a movie up by title to see (`/rentals/Jaws`)
- Look a movie up by id to see (`/movies/rentals/2`)
- it's synopsis
- release date
- available inventory (not currently checked-out to a customer)
- available inventory (not currently checked-out to a customer)
- and inventory total
- See a list of customers that have _currently_ checked out any of the movie's inventory (`/rentals/Jaws/customers`)
- See a list of customers that have _currently_ checked out any of the movie's inventory (`/movies/rentals/:movie_id/customers`)
- Given a customer's `id` and a movie's `title` ...
- "check out" one of the movie's inventory to the customer (`/rentals/Jaws/check-out`)
- "check out" one of the movie's inventory to the customer POST (`/movies/rentals/:movie_id/check-out/:customer_id`)
- Establish a return date
- Charge the customer's account (cost up to you)
- "check in" one of customer's rentals (`/rentals/Jaws/return`)
- "check in" one of customer's rentals POST (`/movies/rentals/:movie_id/return/:customer_id`)
- return the movie to its inventory
- See a list of customers with overdue movies (`/rentals/overdue`)
- See a list of customers with overdue movies (`/movies/rentals/overdue`)
- include customer name, movie title, check-out date, and return date

#### Testing
- All endpoints must be tested.
- We will use [Jasmine](https://github.com/mhevery/jasmine-node) for tests.
- There isn't a coverage requirement for this project, beyond demonstrating that every endpoint is covered by some manner of tests.
=================================

####Visual tree
All urls are from root (localhost:3000/)

- (`/customers`) (All customers)
- (`/customers/sort/:sort_params`) (Some customers)
+ `name` : (`/name?n=10&p=2`) (sorted by name)
+ `registered_at` : (`/registered-at?n=10&p=2`) (sortedby join date)
+ `postal_code` : (`/postal-code?n=10&p=2`) (sorted by location)
- (`/customers/:customer_id/current`) (Currently checked out movies by a customer)
- (`/customers/:customer_id/history`) (Previously checked out movies by a customer)


- (`/movies`) (All movies)
- (`/movies/sort/:sort_params`) (Some movies)
+ `title` : (`/title?n=5&p=1`) (Sorted by title)
+ `release_date` : (`/release-date?n=5&p=1`) (Sorted by release date)
- (`/movies/:movie_id/current`) (Current rentals per movie, ordered by due date)
- (`/movies/:movie_id/history/sort/:sort_params`) (Some customers who have previously checked out movies)
+ (`/movies/:movie_id/history/sort/name`) (Sort by customer name)
+ (`/movies/:movie_id/history/sort/date`) (Sort by check-out date)

#####[Rentals, an extension of Movies]
- (`/movies/rentals/:movie_id`) (To see movie details, and number of available copies in addition to total stock)
- (`/movies/rentals/:movie_id/customers`) (Customers who currently have this movie checked out)
- POST (`/movies/rentals/:movie_id/check-out/:customer_id`) (Creates a "check-out" of this movie to this customer, assigning the record a due date and charge)
- POST (`/movies/rentals/:movie_id/return/:customer_id`) ("Returns" this movie checked out to this customer, changing checked-out status to false, and changing the available inventory accordingly)
- (`/movies/rentals/overdue`)

##Informational endpoints
- (`/api/docs`) (Serves a *HTML view* of documentation)
- (`/api/docs.json`) (Serves JSON documentation)
11 changes: 10 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

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

var app = express();

var massive = require("massive")
var connectionString = "postgres://localhost/video_store"

// divide responsibilities. everything in "movies" will have /movies in its url.
var movies = require('./routes/movies');
app.use('/movies', movies)

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

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
Expand Down
90 changes: 90 additions & 0 deletions controllers/customers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
var Massive = require("massive");
var db = Massive.connectSync({db : "video_store"});

var CustomerController = {
allCustomers: function (req, res, next) {
db.query("select * from customers", function(err, customerRecords){
if(err) {
var err = new Error(err.message)
next(err)
} else {
res.json(customerRecords)
}
});
},

sortName: function (req, res, next) {
var n = req.query.n
var p = req.query.p
if (n === undefined) { n = 10 }
if ( p === undefined) { p = 1 }
db.query("select * from customers order by name asc limit $1 offset $2", [n, p], function(err, customerRecords){
if(err) {
var err = new Error(err.message)
next(err)
} else {
res.json(customerRecords)
}
});
},

sortDate: function (req, res, next) {
var n = req.query.n
var p = req.query.p
if ( n === undefined) { n = 10 }
if ( p === undefined) { p = 1 }
db.query("select * from customers order by registered_at asc limit $1 offset $2", [n, p], function(err, customerRecords){
if(err) {
var err = new Error(err.message)
next(err)
} else {
res.json(customerRecords)
}
});
},

sortPostalCode: function (req, res, next) {
var n = req.query.n
var p = req.query.p
if ( n === undefined) { n = 10 }
if ( p === undefined) { p = 1 }
db.query("select * from customers order by postal_code asc limit $1 offset $2", [n, p], function(err, customerRecords){
if(err) {
var err = new Error(err.message)
next(err)
} else {
res.json(customerRecords)
}
});
},

current: function (req, res, next) {
var customerId = req.params.id
db.query("select * from rentals where checked_out = true and customer_id=$1 order by due_date asc", [customerId], function(err, movieRecords){
if(err) {
var err = new Error(err.message)
next(err)
} else if (movieRecords.length < 1) {
res.json("This customer has not yet checked out any movies")
} else {
res.json(movieRecords)
}
});
},

history: function (req, res, next) {
var customerId = req.params.id
db.query("select * from rentals where checked_out = false and customer_id=$1 order by due_date asc", [customerId], function(err, movieRecords){
if(err) {
var err = new Error(err.mesage)
next(err)
} else if (movieRecords.length < 1) {
res.json("This customer has not yet checked out any movies")
} else {
res.json(movieRecords)
}
});
}
}

module.exports = CustomerController
Loading