Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
f06844d
Merge pull request #1 from natalie-perret/migrations
kelly-keating May 11, 2017
c009838
Merge pull request #2 from natalie-perret/routes
kelly-keating May 11, 2017
74468e2
Add 3 seed files
May 11, 2017
2adad62
Merge pull request #3 from natalie-perret/nat-seeds
natalie-perret May 11, 2017
5088e79
added 2 passing tests and prepared files for postgres
simonol1 May 11, 2017
96caacf
Merge pull request #4 from natalie-perret/1team1dream
simonol1 May 11, 2017
5c3bbef
Add readme file
May 11, 2017
110eaab
Merge pull request #5 from natalie-perret/nat-seeds
natalie-perret May 11, 2017
54f48fe
Delete 20160802144759_users.js
natalie-perret May 11, 2017
6b28235
Update and rename index.hbs to main.hbs
hannahbeale May 11, 2017
054ab04
Create addmovie.hbs
hannahbeale May 11, 2017
53e80f0
Create home.hbs
hannahbeale May 11, 2017
4d20065
Create movie.hbs
hannahbeale May 11, 2017
08f1b57
added tests for addmovie and movie by id
simonol1 May 11, 2017
f21bccb
add public
hannahbeale May 11, 2017
457f499
add public
hannahbeale May 11, 2017
dc493c7
corrected bodyparser in server.js
simonol1 May 11, 2017
59447d8
Merge branch 'routes' into master
kelly-keating May 11, 2017
f126ed7
change romance number
kelly-keating May 11, 2017
59c4009
json called
kelly-keating May 11, 2017
fcc3237
adjusted movie id
simonol1 May 11, 2017
05f959f
Merge pull request #8 from natalie-perret/1team1dream
simonol1 May 11, 2017
b0346a7
Added .gitignore
kelly-keating May 11, 2017
d7962b1
Add form options
May 11, 2017
4baa27d
fixed ignore
Pouramua May 11, 2017
5dc71ea
Merge pull request #9 from natalie-perret/fixmaster
kelly-keating May 11, 2017
eeb09d9
Merge pull request #10 from natalie-perret/nat-addMovieForm
natalie-perret May 11, 2017
aa5a32c
moved tests back
Pouramua May 12, 2017
59395b4
Merge branch 'master' of https://github.com/natalie-perret/movie-rand…
Pouramua May 12, 2017
cae3204
moved views
Pouramua May 12, 2017
bdd3358
pushing
hannahbeale May 12, 2017
37a0a25
Merge branch 'master' into helphannah
kelly-keating May 12, 2017
189d3b3
Merge pull request #11 from natalie-perret/helphannah
kelly-keating May 12, 2017
a20d996
all merge before lunch
Pouramua May 12, 2017
078b4ed
Update knexfile.js
kelly-keating May 12, 2017
f33e01e
Update server.js
kelly-keating May 12, 2017
228acdc
Update server.js
kelly-keating May 12, 2017
27071ad
styling in progress
hannahbeale May 12, 2017
1abc62b
movie genres written
Pouramua May 12, 2017
b7ff58d
Merge pull request #12 from natalie-perret/routes-afternoon
kelly-keating May 12, 2017
90e974b
Merge branch 'master' of https://github.com/natalie-perret/movie-rand…
May 12, 2017
5f3bbd9
Select form added to home page
May 12, 2017
6af891d
added 2 function tests
simonol1 May 12, 2017
d9c247a
Merge pull request #13 from natalie-perret/style-form
natalie-perret May 12, 2017
1d1a507
6 passing tests
simonol1 May 12, 2017
57930cb
working on css
hannahbeale May 12, 2017
7b3c093
Merge branch 'master' into style
hannahbeale May 12, 2017
380fd2d
Merge pull request #14 from natalie-perret/style
hannahbeale May 12, 2017
b7a4a24
Update home.hbs
natalie-perret May 12, 2017
0cf2fdf
Update main.css
natalie-perret May 12, 2017
23ca539
post random gets genre
Pouramua May 12, 2017
6d0c8ba
Merge branch 'master' into testing
simonol1 May 12, 2017
fa1dc04
Merge pull request #15 from natalie-perret/testing
simonol1 May 12, 2017
d10775b
Remove empty box from home page
May 12, 2017
0fb6b44
Merge pull request #16 from natalie-perret/thomasin-stuff
natalie-perret May 12, 2017
760e8af
hello
thomasin May 12, 2017
3637fa5
genreId working
Pouramua May 12, 2017
f41d979
Merge branch 'master' into api-integration
natalie-perret May 12, 2017
2d13558
Merge pull request #17 from natalie-perret/api-integration
natalie-perret May 12, 2017
0b95aa1
Update addmovie.hbs
natalie-perret May 12, 2017
dc0200d
Update db.js
natalie-perret May 12, 2017
f9e5cb8
randomise created
Pouramua May 12, 2017
93c7b37
Working site
May 12, 2017
6586ea9
Random search function working
May 12, 2017
0b1a086
Merge pull request #18 from natalie-perret/more-css
natalie-perret May 12, 2017
b255cdb
finished randomise
Pouramua May 12, 2017
7b7b865
wjkhEFBKJhe
thomasin May 12, 2017
9643f6c
Add to database working
thomasin May 12, 2017
267e885
randomise is DONE
Pouramua May 12, 2017
1489ca5
Merge branch 'master' into routes-afternoon
natalie-perret May 12, 2017
a89133e
Merge pull request #19 from natalie-perret/routes-afternoon
natalie-perret May 12, 2017
852931d
Update db.js
natalie-perret May 12, 2017
c422a6c
add extra bracket
May 12, 2017
9d2d808
Code freeze time
May 12, 2017
e6b7cdb
add home button
May 12, 2017
e562908
New migration change type
simonol1 May 12, 2017
6ee6b6b
updated the readme
simonol1 Aug 2, 2017
64f1c89
Merge pull request #20 from natalie-perret/simon
simonol1 Aug 2, 2017
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
36 changes: 0 additions & 36 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,39 +1,3 @@
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

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

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# 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 directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

dev.sqlite3
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# Boilerplate: Knex.js
# Movie-randomiser
An app with a big button that lets you randomly choose a movie to watch (by genre if you want).

Phase 1 boilerplate project with:
### User stories
* I want to watch a movie with my class but we can't decide on what movie to watch.
* I'm at home and I want to be able ot pick an actor or actress that I like, then click a button to randomly generate a movie.

- Express
- Knex
- SQLite3
- Express Handlebars
- body-parser
- AVA
- Node Inspector
- nodemon
### MVP
* An app with a big button to click on which randomly selects a movie to watch (by genre if desired).
* Have a drop down menu that allows user to select either 'All' genres or by a specific genre.
* Have a database for movies with a title, year and blurb column.
* Have a database with a bunch of genre options.
* Have a database which joins movies with their genres (as some movies may have more than one genre).

### Stretch
* A user can add more movies to the database through a form

## Install

```
npm install
npm run knex migrate:latest
npm run knex seed:run
npm run dev
```

Be sure to check out the other npm scripts too.
### Instructions for use:
- Open up Terminal and type the following:
- Git clone https://github.com/natalie-perret/movie-randomiser.git
- Navigate to the movie-randomiser repository
- npm install
- Open the repository using your favourered text editor
- Open a browser and visit localhost:3000
- Click on the movie randomiser. Enjoy
142 changes: 139 additions & 3 deletions db.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,158 @@

var movieDb = require('moviedb')('5d6500fd40637e64552fe0ce86c7e9ca')

function allGenres (connection) {
return connection('genres').select(name)
}

function allMovies (connection) {
return connection('movies')
}

function getMovie (id, connection) {
return connection('movies').select()
.where('id', id)
.first()
}

function genreId (name, connection) {
return connection('genres').select('id')
.where('name', name)
.first()
}

function getMovieGenres (movieId, connection) {
return connection('genres')
.join()
}


function addRandom(connection) {
getLatestMovie()
.then(findById)
.then((result) => {
connection('movies')
.insert({
title: result.original_title,
year: result.release_date.slice(0,4) || "No release date data",
blurb: result.overview || "No description data"
})
.then((movieid) => {
connection('types')
.insert({
movie_id: movieid,
genre_id: 15
})
})
.then((result) => {
console.log(result)
})
})
.catch(console.log)
}


function allGenres(connection) {
return connection('genres').select('name')
}

function getLatestMovie() {
return new Promise((resolve, reject) => {
movieDb.miscLatestMovies((err, res) => {
if (err) {
reject(err)
}
resolve(res)
})
})
}


function findById(result) {
let randId = Math.floor(Math.random() * result.id) + 1
return new Promise((resolve, reject) => {
movieDb.movieInfo({id: randId}, (err, res) => {
if (err) {
if (err.response.body.status_code != 34) { reject(err) }
resolve(findById(result))
}
resolve(res)
})
})
}

function getMovieGenres (movieId, connection) {
return connection('genres')
.join('types', 'genre_id', '=', 'genres.id')
.where('movie_id', movieId)
}


function getGenreMovies (genreId, connection) {
return connection('movies')
.join('types', 'movie_id', '=', 'movies.id')
.where('genre_id', genreId)
}

function randomise(movies) {
return new Promise ((resolve, reject) => {
var size = movies.length
if (size == 0) reject("No movies in db of this genre")
var pick = Math.floor(Math.random() * size)
console.log(pick);
resolve(movies[pick])
})
}

function searchMovies(keyword) {
return new Promise((resolve, reject) => {
movieDb.searchMovie({query: keyword}, (err, result) => {
if (err) {
console.log(err)
reject(err)
} else {
resolve(result)
}
})
})
}

function addTitle(movie_id, connection) {
return new Promise((resolve, reject) => {
movieDb.movieInfo({id: movie_id}, (err, res) => {
if (err) {
console.log(err)
reject(err)
}
connection('movies')
.insert({
title: res.original_title,
year: res.release_date.slice(0,4) || "No release date data",
blurb: res.overview || "No description data"
})
.then((movieid) => {
return connection('types')
.insert({
movie_id: movieid,
genre_id: 15
})
})
.then((result) => {
resolve(res)
})
})
})
}

module.exports = {
allGenres: allGenres,
getMovie: getMovie,
getMovieGenres: getMovieGenres
allMovies: allMovies,
genreId: genreId,
getGenreMovies: getGenreMovies,
randomise: randomise,
searchMovies,
addRandom,
addTitle,
allGenres,
getMovie,
getMovieGenres
}
11 changes: 0 additions & 11 deletions migrations/20160802144759_users.js

This file was deleted.

2 changes: 1 addition & 1 deletion migrations/20170512095626_movies.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.up = function (knex, Promise) {
table.increments('id').primary()
table.string('title')
table.string('year')
table.string('blurb')
table.text('blurb')
})
}

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"body-parser": "^1.16.0",
"express": "^4.14.1",
"express-handlebars": "^3.0.0",
"knex": "^0.12.6"
"knex": "^0.12.6",
"moviedb": "^0.2.8",
"pg": "^6.1.5"
}
}
76 changes: 76 additions & 0 deletions public/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
font-family: 'Raleway', sans-serif;


* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
-box-sizing: border-box;


}

.headerbox{

border-radius: 25px;
border: 25px solid white;
padding: 25px;
margin: 25px;
text-align: center;
}

.header {
font-family: 'Ubuntu', sans-serif;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 0px

}

body{
font-family: 'Raleway', sans-serif;
background-image: url("https://i.ytimg.com/vi/JvIONJQ54Mw/maxresdefault.jpg");
background-size: cover;
background-repeat: no-repeat;
color: white;
}

.bigbox{

border-radius: 25px;
border: 25px solid white;
padding: 25px;
margin: 25px;
text-align: center;
}

h1 {
font-size: 12rem
}

#genreList {
color: black
}

input[type=submit] {
margin: 20px;
color: white;
background-color: blue;
border: 2px;
cursor: pointer;
}

input[type=text] {
margin: 20px;
color: black;
background-color: white;
border: 2px;
cursor: pointer;
}

button[type=submit] {
margin: 20px;
color: white;
background-color: blue;
border: 2px;
cursor: pointer;
}
Loading