Skip to content

Commit

Permalink
Merge branch 'AddingBackend' of https://github.com/Tushar3099/DHWANI
Browse files Browse the repository at this point in the history
…into AddingBackend
  • Loading branch information
Tushar3099 committed Jun 10, 2020
2 parents b825406 + 517dc37 commit 709e6ec
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 54 deletions.
6 changes: 3 additions & 3 deletions Server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var seedDB=require("./seed");
var IndexRoutes=require("./routes/IndexRoute");
var SongRoutes=require("./routes/songsRoute");
// var ArtistRoutes=require("./routes/ArtistRoute");
// var ReviewRoutes=require("./routes/reviewsRoute");
var ReviewRoutes=require("./routes/reviewsRoute");
var PlaylistRoutes=require("./routes/playlistRoute");
// var ModeratorRoutes=require("./routes/ModeratorRoute");

Expand All @@ -27,9 +27,9 @@ seedDB();


app.use(IndexRoutes);
app.use("/song",SongRoutes);
app.use(SongRoutes);
// app.use("/artists",ArtistRoutes);
// app.use("/songs/:id/reviews", ReviewRoutes);
app.use(ReviewRoutes);
app.use(PlaylistRoutes);
// app.use(ModeratorRoutes);

Expand Down
4 changes: 4 additions & 0 deletions Server/models/song.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var songSchema= new mongoose.Schema({
type: String,
default:"https://assets.audiomack.com/default-song-image.jpg"
},
duration:{
type: Number,
default: 5.05
}
});

module.exports = mongoose.model("Song",songSchema);
94 changes: 48 additions & 46 deletions Server/routes/IndexRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,112 +17,114 @@ router.get("/search/:type/:keyword",(req,res) => {
if(type.toLowerCase()=="song")
{

Song.find({name: { "$regex": keyword, "$options": "i" }}).populate('artist','fullname').exec(function(err,song){
Song.find({name: { "$regex": keyword, "$options": "i" }}).populate('artist','fullname').exec(async function(err,song){
// Song.find({name: new RegExp('\\b' + keyword + '\\b', 'i')}).populate('artist','fullname').exec(function(err,song){
song.forEach(function(song){
await song.forEach(async function(song){
var art=[];
song.artist.forEach(function(artist){
await song.artist.forEach( function(artist){
art.push(artist.fullname);
});
sdata.push({
await sdata.push({
_id: song._id,
name: song.name,
artist: art,
image: song.image,
rating: song.rating,
genre: song.genre,
mood: song.mood

});
});
res.send(sdata);
mood: song.mood,
duration: song.duration
});
});
await res.send(sdata);
// console.log(song)
});

}
if(type.toLowerCase()=="artist"){
Song.find({}).populate('artist','fullname').exec(function(err,songs){
songs.forEach(function(song){
song.artist.forEach(function(artist){
Song.find({}).populate('artist','fullname').exec(async function(err,songs){
await songs.forEach(function(song){
song.artist.forEach(async function(artist){
// var regx=/artist.fullname/i;
var regx=new RegExp(keyword, 'i')
if(regx.test(artist.fullname)){
// console.log("aa");
var art=[];
song.artist.forEach(function(artist){
await song.artist.forEach(function(artist){
art.push(artist.fullname);
});
sdata.push({
await sdata.push({
_id: song._id,
name: song.name,
artist: art,
image: song.image,
rating: song.rating,
genre: song.genre,
mood: song.mood

});
}
})

mood: song.mood,
duration: song.duration
});
}
})
});
// songs.find({"artist.fullname" : { "$regex": keyword, "$options": "i" }},function(err,results){
res.send(sdata);
await res.send(sdata);
});

}
if(type.toLowerCase()=="mood"){
Song.find({},function(err,songs){
songs.forEach(function(song){
song.mood.forEach(function(mood){
Song.find({}).populate('artist','fullname').exec(async function(err,songs){
await songs.forEach( function(song){
song.mood.forEach(async function(mood){
var regx=new RegExp(keyword, 'i')
if(regx.test(mood)){
var art=[];
song.artist.forEach(function(artist){
art.push(artist.fullname);
});
sdata.push({
_id: song._id,
name: song.name,
artist: art,
image: song.image,
rating: song.rating,
genre: song.genre,
mood: song.mood

});
var art=[];
await song.artist.forEach(function(artist){
art.push(artist.fullname);
// console.log(artist.fullname);
});
await sdata.push({
_id: song._id,
name: song.name,
artist: art,
image: song.image,
rating: song.rating,
genre: song.genre,
mood: song.mood,
duration: song.duration
});

}
});

});
res.send(sdata);
await res.send(sdata);
});

}
if(type.toLowerCase()=="genre"){
Song.find({},function(err,songs){
songs.forEach(function(song){
song.genre.forEach(function(genre){
Song.find({}).populate('artist','fullname').exec(async function(err,songs){
await songs.forEach(function(song){
song.genre.forEach(async function(genre){
var regx=new RegExp(keyword, 'i')
if(regx.test(genre)){
var art=[];
song.artist.forEach(function(artist){
await song.artist.forEach(function(artist){
art.push(artist.fullname);
});
sdata.push({
await sdata.push({
_id: song._id,
name: song.name,
artist: art,
image: song.image,
rating: song.rating,
genre: song.genre,
mood: song.mood
mood: song.mood,
duration: song.duration

});
}
});
});
res.send(sdata);
await res.send(sdata);
});
}
});
Expand Down
35 changes: 34 additions & 1 deletion Server/routes/ModeratorRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,37 @@ var Song=require('../models/song');
var RequestSong=require('../models/requestSong');
var Playlist=require('../models/playlist');

module.exports=router();
router.get('/admin',function(req,res){
RequestSong.find({}).populate('artist').exec(function(err,songs){
var sdata=[];
songs.forEach(function(song){
var ar=[];
song.artist.forEach(function(art){
ar.push(art.fullname)
})
sdata.push({
_id: song._id,
name: song.name,
image: song.image,
artist: ar,
mood: song.mood,
genre: song.genre,
duration: song.duration,
});
});
res.send(sdata);
});
});
router.get('/approve/:id',function(req,res){
RequestSong.findById(req.params.id,function(err,aprovedsong){
Song.create(approvedsong,function(err,data){
if(!err){
RequestSong.findByIdAndRemove(req.params.id,function(err){
res.redirect("/admin");
});
}

})
})
})
module.exports=router;
81 changes: 78 additions & 3 deletions Server/routes/playlistRoute.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
var express=require("express");
var router=express.Router({mergeParms: true});
var bodyParser=require('body-parser');
var router=express.Router({mergeParms: true
});

router.use(bodyParser.urlencoded({extended:true}));
var User=require('../models/user');
var Review=require('../models/review');
var Song=require('../models/song');
var RequestSong=require('../models/requestSong');
var Playlist=require('../models/playlist');

router.get("/playlist", function(req,res){
Playlist.find({},(err,playlists)=>{
var vid1="5edf37648724f237e0d8f760",
vid2="5edf37648724f237e0d8f761";
// Playlist.find({createdBy:vid1},(err,playlists)=>{
Playlist.find({createdBy:req.user._id},(err,playlists)=>{
if(err){
console.log(err);
}
Expand All @@ -19,10 +25,79 @@ router.get("/playlist", function(req,res){
name: play.name,
image: play.image,
length: play.length,
_id: play._ids
_id: play._id,
createdBy: play.createdBy
});
});
res.send(sdata);
});
});
router.get("/playlist/:id",function(req,res){
Playlist.findById(req.params.id).populate('songs').populate('createdBy').exec(function(err,play){
// console.log(play.createdBy);
var vid1="5edf37648724f237e0d8f760",
vid2="5edf37648724f237e0d8f761";
// if(play.createdBy._id==vid1){
if(play.createdBy._id==req.user_id){
var songs1=[];
play.songs.forEach(function(playsong){
songs1.push({
name: playsong.name,
_id: playsong._id,
// artist: playsong._artist,
mood: playsong.mood,
genre: playsong.genre,
duration: playsong.duration

});
});
var sdata={
_id: play._id,
name: play.name,
// createdBy: play.createdBy,
image: play.image,
length: play.length,
songs: songs1
}

}
res.send(sdata);

});
});
router.post("/playlist",function(req,res){
var vid1="5edf37648724f237e0d8f760",
vid2="5edf37648724f237e0d8f761";
// console.log(req);
var newp={
name: req.query.name,
createdBy: req.user._id,
// createdBy: vid1
}
// console.log(newp);
Playlist.create(newp,function(err,playlist){
res.redirect("/playlist/"+playlist._id);
});
});
router.get("/playlist/:pid/song/:sid",function(req,res){
Playlist.findById(req.params.pid,function(err,playlist){
var vid1="5edf37648724f237e0d8f760",
vid2="5edf37648724f237e0d8f761";
// if(playlist.createdBy==vid1){
if(playlist.createdBy==req.user._id){
Song.findById(req.params.sid,function(err,song){
playlist.songs.push(song);
playlist.save(function(err,play){
res.redirect("/playlist/"+req.params.pid);
});
});
}
else{
res.redirect("/playlist");
}


})
});

module.exports=router;
45 changes: 44 additions & 1 deletion Server/routes/reviewsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,47 @@ var Song=require('../models/song');
var RequestSong=require('../models/requestSong');
var Playlist=require('../models/playlist');

module.exports=router();
router.get("/song/:id/review",function(req,res){
// console.log(req.params.id);
Song.findById(req.params.id).populate({
path: 'review',
populate: {
path: 'createdBy',
model: 'User'
}
}).exec(function(err,song){
// console.log(song);
var sdata=[];
song.review.forEach(function(review){
sdata.push({
content: review.content,
createdBy: review.createdBy.fullname,
rating: review.rating,
songid: song._id,
date: review.dateCreated.toDateString()
});
});
res.send(sdata);
});
});
router.post("/song/:id/review",function(req,res){
var vid1="5edf37648724f237e0d8f760",
vid2="5edf37648724f237e0d8f761";
var newrev={
content: req.query.content,
// createdBy: vid2,
createdBy: req.user._id,
rating: req.query.rating,
};
Review.create(newrev,function(err,rev){
Song.findById(req.params.id,function(err,fsong){
fsong.rating = ((fsong.rating*fsong.review.length)+rev.rating)/(fsong.review.length+1);
fsong.review.push(rev);
fsong.save(function(err,song){
res.redirect("/song/"+req.params.id+"/review");
});
});
});

});
module.exports=router;
Loading

0 comments on commit 709e6ec

Please sign in to comment.