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

Zach - Submission - tunr_express #168

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8daf711
created basic file/folder structure, dummy functions to test routing …
zachariah-chow Apr 16, 2020
c538ce6
created sql files for artists / songs tables
zachariah-chow Apr 16, 2020
3b3fc11
added getArtistById controller & basic view
zachariah-chow Apr 16, 2020
ed5b189
added edit artist controller / basic view / script for input validati…
zachariah-chow Apr 16, 2020
e79a7ca
added deleteArtist, addArtist controllers
zachariah-chow Apr 16, 2020
901e3ac
added basic styles for landing page, added featured artist, modified …
zachariah-chow Apr 17, 2020
95b7a0c
fixed client connection leak in db script
zachariah-chow Apr 17, 2020
6bf0444
added get /songs /songs:id controllers/views, updated styles (incl. o…
zachariah-chow Apr 18, 2020
f7f8e7b
completed songs controllers, added scaffolding for songs views
zachariah-chow Apr 18, 2020
fbcb57f
added ON DELETE CASCADE constraint to artist_id fkey
zachariah-chow Apr 18, 2020
44663cd
minor syntax changes to controllers
zachariah-chow Apr 18, 2020
ace4771
updated nav bar styles, modified elements of views
zachariah-chow Apr 18, 2020
78457c0
fixed bug in getAllSongs controller
zachariah-chow Apr 18, 2020
b5eb809
added file structure and dummy controllers to test playlist routes
zachariah-chow Apr 19, 2020
d106756
added get-date util for playlists
zachariah-chow Apr 19, 2020
291d177
added sql files for playlists and playlists_songs
zachariah-chow Apr 19, 2020
a0c0c32
added get playlist form, handlers for add/delete song btns and artist…
zachariah-chow Apr 19, 2020
97a4bd2
added postAddPlaylist controller
zachariah-chow Apr 19, 2020
8fec281
added blank models files
zachariah-chow Apr 19, 2020
238c424
fixed query in getAllSongs controller (to order by id)
zachariah-chow Apr 19, 2020
33d1866
added deletePlaylistById controller
zachariah-chow Apr 19, 2020
6b05621
added edit-playlist-form script
zachariah-chow Apr 19, 2020
7ddf8bc
basic views for playlists, added putEditPlaylist controller
zachariah-chow Apr 19, 2020
ac626fc
added wrappers for forms, updated form styles
zachariah-chow Apr 19, 2020
86179af
fixed redirect in postAddPlaylist controller
zachariah-chow Apr 19, 2020
c3d4013
updated styles:- 404page, playlists views
zachariah-chow Apr 19, 2020
6cec325
fixed minor syntax re: value vs defaultValue
zachariah-chow Apr 19, 2020
b4bf09f
added songs model, refactored songs controller
zachariah-chow Apr 19, 2020
8c3295f
added artist model, refactored artists controller
zachariah-chow Apr 19, 2020
8f9a345
completed refactoring of artist controller vis artist model
zachariah-chow Apr 19, 2020
c7f7068
added partial playlist model, partial refactoring of playlist controller
zachariah-chow Apr 19, 2020
a91ffeb
added auth routes, dummy auth controllers, basic session middleware
zachariah-chow Apr 20, 2020
ca89cc1
added basic logic for postLogin and postRegister controllers, with te…
zachariah-chow Apr 20, 2020
b8a4c1f
added basic views for getLogin, getRegister, home(w/ login & register)
zachariah-chow Apr 20, 2020
4b9e033
added visits cookie counter
zachariah-chow Apr 20, 2020
f8e37fa
added logic for userId / visits interaction, store user visits in loc…
zachariah-chow Apr 21, 2020
0e388e0
added user model file
zachariah-chow Apr 21, 2020
ec90083
added users and favourites tables.sql
zachariah-chow Apr 21, 2020
32edb1d
added basic controllers for auth routes (db)
zachariah-chow Apr 21, 2020
acfcb1e
added login / register input validation, basic styles for home page (…
zachariah-chow Apr 21, 2020
6f8f1d8
added controller/route files for favourites
zachariah-chow Apr 21, 2020
3e023d1
added postFavourites controller
zachariah-chow Apr 21, 2020
75b7f02
added delete & getall favs controller, fav-all views
zachariah-chow Apr 21, 2020
ed839c2
updated styles
zachariah-chow Apr 21, 2020
b0b546a
changed user in db.js
zachariah-chow Apr 23, 2020
ee16da8
reverted to previous db user config
zachariah-chow Apr 23, 2020
0dd2ae1
user config
zachariah-chow Apr 23, 2020
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
3 changes: 3 additions & 0 deletions controllers/404-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports.get404Page = (req, res) => {
res.status(404).render('404');
}
65 changes: 65 additions & 0 deletions controllers/artists-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const db = require('../util/database.js');

module.exports.getArtistById = async (req, res) => {

const { id } = req.params;
const queryT = `SELECT * FROM artists WHERE id=${id}`
const { rows } = await db.query(queryT);

res.render('./artists/artist-single', { 'singleArtist': rows[0] });

}

module.exports.getAllArtists = async (req, res) => {

const { rows } = await db.query('SELECT * FROM artists');

res.render('./artists/artist-all', { 'allArtists': rows });

}

module.exports.getAddArtist = async (req, res) => {
res.render('./artists/add-artist');
}

module.exports.postAddArtist = async (req, res) => {

const queryT = `INSERT INTO artists(name, nationality, photo_url) VALUES($1, $2, $3) RETURNING *`;
const queryV = [req.body.name, req.body.nationality, req.body['image link']];
const { rows } = await db.query(queryT, queryV);

res.redirect(`./${rows[0].id}`);

}

module.exports.getEditArtistById = async (req, res) => {

const { id } = req.params;
const queryT = `SELECT * FROM artists WHERE id=${id}`
const { rows } = await db.query(queryT);

res.render('./artists/edit-artist', {
'singleArtist': rows[0]
});

}

module.exports.putArtistById = async (req, res) => {


const { id } = req.params;
const queryT = `UPDATE artists SET name = '${req.body.name}', nationality = '${req.body.nationality}', photo_url = '${req.body['image link']}' WHERE id=${id}`
const { rows } = await db.query(queryT);

res.redirect(`./${id}`);

}

module.exports.deleteArtistById = async (req, res) => {

const { id } = req.params;
const queryT = `DELETE from artists WHERE id=${id}`
const { rows } = await db.query(queryT);
res.render('./artists/artist-deleted');

}
35 changes: 35 additions & 0 deletions controllers/songs-controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const db = require('../util/database.js');

module.exports.getArtistSongById = async (req, res) => {
// const { id } = req.params;
// const { rows } = await db.query('SELECT * FROM songs where id = $1', [id]);
console.log('Get Artist Song By Id');
res.send('Get Artist Song By Id');
}

module.exports.getAllSongsOfArtist = async (req, res) => {
// const { id } = req.params;
// const { rows } = await db.query('SELECT * FROM songs');
console.log('Get All Songs');
res.send('Get All Songs');
}

module.exports.postAddSongToArtist = async (req, res) => {
console.log('Add New Artist!');
res.send('Add New Artist!');
}

module.exports.getEditArtistSongById = async (req, res) => {
console.log('Get Edit Artist Form By Id!');
res.send('Get Edit Artist Form By Id!');
}

module.exports.putArtistSongById = async (req, res) => {
console.log('Artist Edited!');
res.send('Artist Edited!');
}

module.exports.deleteArtistSongById = async (req, res) => {
console.log('Delete Artist Form By Id!');
res.send('Delete Artist Form By Id!');
}
5 changes: 3 additions & 2 deletions artist_data.sql → db/artist_data.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
INSERT INTO artists(name, photo_url, nationality) VALUES('Yeah Yeah Yeahs', 'http://www.athousandguitars.com/wp-content/uploads/2013/04/yeah-yeah-yeahs.jpg', 'USA');
----psql -U zachariah -d tunr_db -a -f ./db/artist_data.sql--
INSERT INTO artists(name, photo_url, nationality) VALUES('Yeah Yeah Yeahs', 'https://www.allthingsgomusic.com/wp-content/uploads/2017/09/Yeah-Yeah-Yeahs-1.jpg', 'USA');
INSERT INTO artists(name, photo_url, nationality) VALUES('Nosaj Thing', 'http://wertn.com/wp-content/uploads/2012/04/Nosaj-Thing_Mondrian_CL_High-3487.jpg', 'USA');
INSERT INTO artists(name, photo_url, nationality) VALUES('Norah Jones', 'http://entertainmentrealm.files.wordpress.com/2012/05/norahjones1.jpg', 'USA');
INSERT INTO artists(name, photo_url, nationality) VALUES('Lykke Li', 'http://www.chartattack.com/wp-content/uploads/2012/07/lykke-li-newmain1-photo-by-daniel-jackson.jpg', 'Sweeden');
INSERT INTO artists(name, photo_url, nationality) VALUES('Kendrick Lamar', 'http://www.xxlmag.com/wp-content/uploads/2013/06/kendricklamar_001-1600.jpg', 'USA');
INSERT INTO artists(name, photo_url, nationality) VALUES('Kendrick Lamar', 'http://www.xxlmag.com/wp-content/uploads/2013/06/kendricklamar_001-1600.jpg', 'USA');
3 changes: 2 additions & 1 deletion songs.sql → db/songs.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--psql -U zachariah -d tunr_db -a -f ./db/songs.sql--
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Maps', 'Fever to Tell', 'http://a1748.phobos.apple.com/us/r1000/074/Music/d4/97/e7/mzm.bigdtgoz.aac.p.m4a', 'http://a3.mzstatic.com/us/r30/Features/d6/ba/99/dj.homcvzwl.60x60-50.jpg', '1');
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Heads Will Roll', 'It''s Blitz! (Deluxe Edition)', 'http://a308.phobos.apple.com/us/r1000/064/Music/9c/a6/3a/mzm.zgjjoqyj.aac.p.m4a', 'http://a1.mzstatic.com/us/r30/Music/4c/30/8c/mzi.gcicgujl.60x60-50.jpg', '1');
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Gold Lion', 'Show Your Bones', 'http://a850.phobos.apple.com/us/r1000/105/Music/d0/b6/fe/mzm.qoeoeazp.aac.p.m4a', 'http://a5.mzstatic.com/us/r30/Features/73/a1/1a/dj.mwlaurzf.60x60-50.jpg', '1');
Expand Down Expand Up @@ -247,4 +248,4 @@
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Bitch, Don’t Kill My Vibe (feat. JAY Z)', 'good kid, m.A.A.d city', 'http://a796.phobos.apple.com/us/r1000/081/Music/v4/64/05/93/640593c0-7a02-3082-e539-a3928c1b3fcf/mzaf_5043431582450077336.aac.m4a', 'http://a4.mzstatic.com/us/r30/Music2/v4/fe/14/11/fe1411bd-77a8-0f69-824a-20145345d9a8/UMG_cvrart_00602537362783_01_RGB72_1500x1500_12UMGIM52988.60x60-50.jpg', '5');
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Swimming Pools (Drank)', 'good kid, m.A.A.d city', 'http://a1265.phobos.apple.com/us/r1000/063/Music/v4/12/0f/13/120f13b3-ba47-2223-d97a-f9ddeae408b6/mzaf_1783459415414390232.aac.m4a', 'http://a1.mzstatic.com/us/r30/Music2/v4/53/ea/bb/53eabb9c-dfaf-b926-cc73-9a1ad6ee548f/UMG_cvrart_00602537362790_01_RGB72_1500x1500_12UMGIM52989.60x60-50.jpg', '5');
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Michael Jordan (feat. Schoolboy Q)', 'Overly Dedicated', 'http://a372.phobos.apple.com/us/r30/Music/ff/b3/1a/mzm.ycpsoiyo.aac.p.m4a', 'http://a2.mzstatic.com/us/r30/Music/7f/4a/12/mzi.onkyvccv.60x60-50.jpg', '5');
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Sing About Me, I''m Dying of Thirst', 'good kid, m.A.A.d city', 'http://a731.phobos.apple.com/us/r1000/081/Music/v4/b8/61/36/b861368e-1960-5b0a-63b7-8cdfc5e0c802/mzaf_9127169611152605592.aac.m4a', 'http://a1.mzstatic.com/us/r30/Music2/v4/53/ea/bb/53eabb9c-dfaf-b926-cc73-9a1ad6ee548f/UMG_cvrart_00602537362790_01_RGB72_1500x1500_12UMGIM52989.60x60-50.jpg', '5');
INSERT INTO songs(title, album, preview_link, artwork, artist_id) VALUES('Sing About Me, I''m Dying of Thirst', 'good kid, m.A.A.d city', 'http://a731.phobos.apple.com/us/r1000/081/Music/v4/b8/61/36/b861368e-1960-5b0a-63b7-8cdfc5e0c802/mzaf_9127169611152605592.aac.m4a', 'http://a1.mzstatic.com/us/r30/Music2/v4/53/ea/bb/53eabb9c-dfaf-b926-cc73-9a1ad6ee548f/UMG_cvrart_00602537362790_01_RGB72_1500x1500_12UMGIM52989.60x60-50.jpg', '5');
8 changes: 8 additions & 0 deletions db/table-artist_data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--psql -U zachariah -d tunr_db -a -f ./db/table-artists_data.sql--

CREATE TABLE artists (
id serial PRIMARY KEY,
name VARCHAR (255) UNIQUE NOT NULL,
photo_url VARCHAR (255),
nationality VARCHAR (255)
);
10 changes: 10 additions & 0 deletions db/table-songs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--psql -U zachariah -d tunr_db -a -f ./db/table-songs.sql--

CREATE TABLE songs (
id serial PRIMARY KEY,
title VARCHAR (255) NOT NULL,
album VARCHAR (255),
preview_link VARCHAR (355),
artwork VARCHAR (355),
artist_id INTEGER REFERENCES artists(id)
);
84 changes: 0 additions & 84 deletions index.js

This file was deleted.

49 changes: 27 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
{
"name": "tunr_express",
"version": "1.0.0",
"description": "We're going to be building Tunr, the worlds #1 music catalog / player (those Spotify haters can't keep up with us).",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://git.generalassemb.ly/ga-wdi-exercises/tunr_sinatra.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"express-react-views": "^0.10.5",
"method-override": "^3.0.0",
"pg": "^7.4.3",
"react": "^16.5.2",
"react-dom": "^16.5.2"
}
}
"name": "tunr_express",
"version": "1.0.0",
"description": "We're going to be building Tunr, the worlds #1 music catalog / player (those Spotify haters can't keep up with us).",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon ./routes/app.js"
},
"repository": {
"type": "git",
"url": "https://git.generalassemb.ly/ga-wdi-exercises/tunr_sinatra.git"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
"express-promise-router": "^3.0.3",
"express-react-views": "^0.10.5",
"method-override": "^3.0.0",
"pg": "^7.4.3",
"react": "^16.5.2",
"react-dom": "^16.5.2"
},
"devDependencies": {
"nodemon": "^2.0.3"
}
}
4 changes: 4 additions & 0 deletions public/css/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* {
margin: 0;
padding: 0;
}
Binary file added public/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions public/scripts/add-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const submitBtn = document.querySelector('.edit-form__submit-btn');

// let nameInput, nationalityInput, imageLinkInput;
// [nameInput, nationalityInput, imageLinkInput] = document.querySelectorAll('.edit-form>input');

submitBtn.addEventListener('click', (ev) => {

invalidMsg = [];

document.querySelectorAll('.add-form>input').forEach(input => {
if (!input.value) invalidMsg.push(input.name)
})

if (invalidMsg.length > 0) {

ev.preventDefault()

let messageEl = document.createElement('p');

messageEl.innerText = invalidMsg.reduce((msg, input) => {
return msg.concat(input, "\n");
}, 'The following fields are empty:\n')

document.querySelector('.add-form').append(messageEl);
}
})
26 changes: 26 additions & 0 deletions public/scripts/edit-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const submitBtn = document.querySelector('.edit-form__submit-btn');

// let nameInput, nationalityInput, imageLinkInput;
// [nameInput, nationalityInput, imageLinkInput] = document.querySelectorAll('.edit-form>input');

submitBtn.addEventListener('click', (ev) => {

invalidMsg = [];

document.querySelectorAll('.edit-form>input').forEach(input => {
if (!input.value) invalidMsg.push(input.name)
})

if (invalidMsg.length > 0) {

ev.preventDefault()

let messageEl = document.createElement('p');

messageEl.innerText = invalidMsg.reduce((msg, input) => {
return msg.concat(input, "\n");
}, 'The following fields are empty:\n')

document.querySelector('.edit-form').append(messageEl);
}
})
Loading