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

SEI 24 Ray #174

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Empty file added .vs/slnx.sqlite
Empty file.
103 changes: 103 additions & 0 deletions controllers/artists.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
module.exports = (db) => {

/**
* ===========================================
* Controller Logic
* ===========================================
*/

let indexControllerCallback = (request, response) => {
response.render('home')
};

let artists = (request,response)=>{
db.artists.getArtists((err,results)=>{
if(err){
console.log("err --- artists in controllers", err.message)
} else {
response.render('./artist/artist',results)
}
});
}

let newArtist = (request,response)=>{
db.artists.getNewArtist((err,results)=>{
if(err){
console.log("err --- newArtist in controllers")
}else {response.render("./artist/new")}
})
}

let postArtist = (request,response)=>{
db.artists.getPostArtist((err,results)=>{
if(err){
console.log("err --- postArtist in controllers",err.message)
}else {response.send(request.body)}
})
}

let idArtist = (request,response)=>{
const values = [request.params.id]
db.artists.getIdArtist(values,(err,results)=>{
if(err){
console.log("err---- idartist in controllers",err.message)
}else {response.render("./artist/id",results.rows[0])}
})
}

let editArtist = (request,response)=>{
db.artists.getEditArtist(request,(err,results)=>{
if(err){
console.log("err ---in edit artist",err.message)
} else {
response.render('./artist/update', results.rows[0])
}
})
};
let updateArtist = (request,response)=>{
db.artists.getUpdateArtist(request,(err,resulst)=>{
if(err){
console.log("err---in update artist",err.message)
} else {
response.redirect(`/artists/${request.params.id}`)
}
})
};

let delArtist = (request,response)=>{
db.artists.getDelArtist(request,(err,results)=>{
if(err){
console.log("err",err.message)
} else {
response.redirect('/artists/')
}
})
};

let allSongsArtist = (request,response)=>{
db.artists.getAllSongsArtist(request,(err,results)=>{
if(err){
console.log("err in all songs artist",err.message)
} else {
response.render('./songs/songs',results)
}
})
};

/**
* ===========================================
* Export controller functions as a module
* ===========================================
*/
return {
index: indexControllerCallback,
artists,
newArtist,
postArtist,
idArtist,
editArtist,
updateArtist,
delArtist,
allSongsArtist
};
}
79 changes: 79 additions & 0 deletions controllers/playlist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
module.exports = (db) => {

/**
* ===========================================
* Controller Logic
* ===========================================
*/

let listPlayList = (request, response) => {
db.playlist.getPlayList((err,results)=>{
if(err){
console.log("err---listplaylist error controller", err.message)
} else {
console.log(results)
response.render('./playlist/home',results)
}
})
};

let newPlayList = (request,response)=>{
response.render('./playlist/new')
}

let createPlayList = (request,response)=>{
let name = request.body.name;
console.log(request.body);
db.playlist.getCreatePlayList(name,(err,results)=>{
if(err){
console.log("err --- createPlayList in controllers")
}else {response.redirect("/playlist")}
})
}

let addSongToPlayList = (request,response)=>{
let id = request.params.id
let obj = {"id":id}
response.render("./playlist/addsong",obj)

}

let addedSongToPlayList = (request,response)=>{
let playListId = request.body.playlist_id;
let songName = request.body.name
// console.log(request.body)
db.playlist.getAddedSongToPlayList(playListId,songName,(err,results)=>{
if(err){
console.log("err ---addedSongToPlayList in controller",err.message)
} else {
response.redirect('/playlist/'+ playListId)
}
})
};

let listPlayListSongs = (request,response)=>{
const values = request.params.id;
db.playlist.getListPlayListSongs(values,(err,results)=>{
if(err){
console.log("err---- idartist in controllers",err.message)
}else {response.render("./playlist/id",results)}
})
}



/**
* ===========================================
* Export controller functions as a module
* ===========================================
*/
return {
listPlayList:listPlayList,
newPlayList,
createPlayList,
addSongToPlayList,
listPlayListSongs,
addedSongToPlayList,
};
}

94 changes: 94 additions & 0 deletions controllers/songs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
module.exports = (db) => {

/**
* ===========================================
* Controller Logic
* ===========================================
*/
let songs = (request,response)=>{
db.songs.getSongs(request,(err,results)=>{
if(err){
console.log("err in songs",err.message)
} else {
response.render('./songs/songslist',results)
}
})
};

let newSong = (request,response)=>{
db.songs.getNewSong(request,(err,results)=>{
if(err){
console.log("err in newSong",err.message)
} else {
response.render('./songs/newsong')
}
})
};

let postSong = (request,response)=>{
db.songs.getPostSong(request,(err,results)=>{
if(err){
console.log("err in post song",err.message)
} else {
response.redirect('/songs')
}
})
};

let idSong = (request,response)=>{
db.songs.getIdSong(request,(err,results)=>{
if(err){
console.log("err in id song",err.message)
} else {
response.render('./songs/songid',results.rows[0])
}
})
};

let editSong = (request,response)=>{
db.songs.getEditSong(request,(err,results)=>{
if(err){
console.log("err",err.message)
} else {
response.render('./songs/songedit',results.rows[0])
}
})
};

let updateSong = (request,response)=>{
let id = request.params.id;
let {title,album,preview_link,artwork} = request.body;
const data = [title, album, preview_link, artwork];
db.songs.getUpdateSong(id,data,(err,results)=>{
if(err){
console.log("err in update song",err.message)
} else {
response.redirect(`/songs/${id}`)
}
})
};

let delSong = (request,response)=>{
db.songs.getDelSong(request,(err,results)=>{
if(err){
console.log("err in del song",err.message)
} else {
response.redirect('/songs/')
}
})
};

/**
* ===========================================
* Export controller functions as a module
* ===========================================
*/
return {
songs: songs,
newSong,
postSong,
idSong,
editSong,
updateSong,
delSong };
}
108 changes: 108 additions & 0 deletions db.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* ===================================================
* ===================================================
* ===================================================
* ===================================================
* ====== CONFIGURATION =========
* ===================================================
* ===================================================
* ===================================================
* ===================================================
*/



const pg = require('pg');
const url = require('url');

var configs;

if( process.env.DATABASE_URL ){

const params = url.parse(process.env.DATABASE_URL);
const auth = params.auth.split(':');

configs = {
user: auth[0],
password: auth[1],
host: params.hostname,
port: params.port,
database: params.pathname.split('/')[1],
ssl: true
};

}else{
configs = {
user: 'postgres',
host: '127.0.0.1',
database: 'tunr_db',
port: 5432
};
}


const pool = new pg.Pool(configs);

pool.on('error', function (err) {
console.log('idle client error', err.message, err.stack);
});



/*
* ===================================================
* ===================================================
* ===================================================
* ===================================================
* ====== REQUIRE MODEL FILES =========
* ===================================================
* ===================================================
* ===================================================
* ===================================================
*/


const allArtistsModelsFunction = require('./models/artists');

const artistsModelsObject = allArtistsModelsFunction( pool );

const allSongsModelsFunction = require('./models/songs');

const songsModelsObject = allSongsModelsFunction( pool );

const allPlayListModelsFunction = require('./models/playlist')

const playListModelsObject = allPlayListModelsFunction( pool );
/*
* ===================================================
* ===================================================
* ===================================================
* ===================================================
* ====== MODULE EXPORTS =========
* ===================================================
* ===================================================
* ===================================================
* ===================================================
*/


module.exports = {
//make queries directly from here
queryInterface: (text, params, callback) => {
return pool.query(text, params, callback);
},

// get a reference to end the connection pool at server end
pool:pool,

/*
* ADD APP MODELS HERE
*/

// users: userModelsObject,
artists: artistsModelsObject,

playlist: playListModelsObject,

songs: songsModelsObject,
};
Loading