Skip to content

Commit

Permalink
Adding Shows To List Implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammadAkthamObeidat committed Jan 14, 2020
1 parent aeac7c6 commit bf0ea61
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 54 deletions.
Binary file modified Wireframe & Prototype/Movies Galaxy - Wire.xd
Binary file not shown.
1 change: 0 additions & 1 deletion controllers/TvShowsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const axios = require("axios");
// API DETAILS.
const API_KEY = "7ba0c7a4a624420802d8a91a4d4fc92c";
const DISCOVER_URL = "https://api.themoviedb.org/3/discover/tv?"
const DETAILS_URL = "https://api.themoviedb.org/3/tv"
const SEARCH_URL = "https://api.themoviedb.org/3/search/tv?"

// Return popular TV-Shows.
Expand Down
19 changes: 12 additions & 7 deletions controllers/UsersController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ deleteMovieFromWatchList = (req, res, next) => {
let userID = req.params.userID;
let movieID = req.params.movieID;
user.deleteMovieFromWatchList(userID, movieID, result => {
console.log('RESULT FROM DELETE MOVIE WATCH LIST RESPONSE : ', result);
res.status(200).json({
status: 'Success Delete Movie From Watch List.',
data: {
Expand All @@ -41,7 +40,6 @@ deleteMovieFromWatchList = (req, res, next) => {
addMovieToWatchedList = (req, res, next) => {
let userID = req.params.userID;
user.addMovieToWatchedList(userID, req.body, result => {
console.log('RESULT FROM WATCHED LIST RESPONSE: ', result);
res.status(200).json({
status: 'Success Add Movie To Watched List.',
data: {
Expand All @@ -56,7 +54,6 @@ deleteMovieFromWatchedList = (req, res, next) => {
let userID = req.params.userID;
let movieID = req.params.movieID;
user.deleteMovieFromWatchedList = (userID, movieID, result) => {
console.log('RESPONSE FROM DELETE MOVIE WATCHED LIST: ', object);
res.status(200).json({
status: 'Success Delete Movie From Watch List.',
data: {
Expand All @@ -74,8 +71,13 @@ deleteMovieFromWatchedList = (req, res, next) => {
addShowToWatchList = (req, res, next) => {
let userID = req.params.userID;
user.addShowToWatchList(userID, req.body, result => {
console.log('RESULT FORM ADD SHOW WATCH LIST: ', result);
//res.json(result);
res.status(200).json({
status: 'Complete',
data: {
addedShow: result
}
})
})
}

Expand All @@ -84,7 +86,6 @@ deleteShowFromWatchList = (req, res, next) => {
let userID = req.params.userID;
let showID = req.params.showID;
user.deleteShowFromWatchList(userID, showID, result => {
console.log('RESULT FORM DELETE SHOW WATCH LIST: ', result);
//res.json(result);
})
}
Expand All @@ -93,8 +94,13 @@ deleteShowFromWatchList = (req, res, next) => {
addShowToWatchedList = (req, res, next) => {
let userID = req.params.userID;
user.addShowToWatchedList(userID, req.body, result => {
console.log('RESULT FORM DELETE SHOW WATCHED LIST: ', result);
//res.json(result);
res.status(200).json({
status: 'Success add to watchedlist.',
data: {
addedShow: result
}
})
})
}

Expand All @@ -103,7 +109,6 @@ deleteShowFromWatchedList = (req, res, next) => {
let userID = req.params.userID;
let showID = req.params.showID;
user.deleteShowFromWatchedList(userID, showID, result => {
console.log('RESULT FORM DELETE SHOW WATCH LIST: ', result);
//res.json(result);
})
}
Expand Down
8 changes: 6 additions & 2 deletions database/DBconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ DB_URI = 'mongodb+srv://mohamad:[email protected]/mov
module.exports = function () {
mongoose.connect(
DB_URI,
{ useUnifiedTopology: true },
{ useFindAndModify: false }
{
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: false,
useCreateIndex: true
}
)

const db = mongoose.connection;
Expand Down
103 changes: 63 additions & 40 deletions models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@ let User = new mongoose.model("User", userSchema);


// Get one user.
let getUser = (user, cb) => {
let getUser = (user, callback) => {
console.log('USER SIGN UP : ', user)
User.find(user, (err, data) => {
if (err) {
cb(err);
User.find(user, (error, data) => {
if (error) {
callback(error);
} else {
cb(data);
callback(data);
}
});
};

// Add new user to database.
let addUser = (newUser, cb) => {
User.create(newUser, (err, data) => {
if (err) {
cb(err);
let addUser = (newUser, callback) => {
User.create(newUser, (error, data) => {
if (error) {
callback(error);
} else {
cb(data);
callback(data);
}
});
};
Expand All @@ -72,7 +72,7 @@ let addUser = (newUser, cb) => {


// Add new movie to watch list.
let addMovieToWatchList = (userID, newMovie, cb) => {
let addMovieToWatchList = (userID, newMovie, callback) => {
User.findOneAndUpdate(
{
_id: userID
Expand All @@ -82,43 +82,44 @@ let addMovieToWatchList = (userID, newMovie, cb) => {
'movies_list.watch_list': newMovie
}
},
(err, data) => {
if (err) {
cb(err);
(error, data) => {
if (error) {
callback(error);
} else {
cb(data);
callback(data);
}
}
);
};

// Delete movie from watch list.
let deleteMovieFromWatchList = (userID, movieID, cb) => {
let deleteMovieFromWatchList = (userID, movieID, callback) => {
User.update(
{ _id: userID },
{
_id: userID
'movies_list.watch_list': movieID
},
{
$pull: {
'movies_list.watch_list': {
'movies_list.$.watch_list': {
id: movieID
}
}
},
(error, data) => {
if (error) {
cb(error)
callback(error)
}
else {
cb(data)
callback(data)
}
}
)
}


// Add new movie to watched list.
let addMovieToWatchedList = (userID, newMovie, cb) => {
let addMovieToWatchedList = (userID, newMovie, callback) => {
User.findOneAndUpdate(
{
_id: userID
Expand All @@ -128,18 +129,18 @@ let addMovieToWatchedList = (userID, newMovie, cb) => {
'movies_list.watched_list': newMovie
}
},
(err, data) => {
if (err) {
cb(err);
(error, data) => {
if (error) {
callback(error);
} else {
cb(data);
callback(data);
}
}
);
};

// Delete movie from watched list.
let deleteMovieFromWatchedList = (userID, movieID, cb) => {
let deleteMovieFromWatchedList = (userID, movieID, callback) => {
User.update(
{
_id: userID
Expand All @@ -150,7 +151,14 @@ let deleteMovieFromWatchedList = (userID, movieID, cb) => {
id: movieID
}
}
}
},
(error, data => {
if (error) {
callback(error)
} else {
callback(data)
}
})
)
}

Expand All @@ -159,7 +167,7 @@ let deleteMovieFromWatchedList = (userID, movieID, cb) => {


// Add new show to watch list.
let addShowToWatchList = (userID, newShow, cb) => {
let addShowToWatchList = (userID, newShow, callback) => {
User.findOneAndUpdate(
{
_id: userID
Expand All @@ -169,18 +177,18 @@ let addShowToWatchList = (userID, newShow, cb) => {
'shows_list.watch_list': newShow
}
},
(err, data) => {
if (err) {
cb(err);
(error, data) => {
if (error) {
callback(error);
} else {
cb(data);
callback(data);
}
}
);
};

// Delete show from watch list.
let deleteShowFromWatchList = (userID, showID, cb) => {
let deleteShowFromWatchList = (userID, showID, callback) => {
User.update(
{
_id: userID
Expand All @@ -191,11 +199,19 @@ let deleteShowFromWatchList = (userID, showID, cb) => {
_id: showID
}
}
},
(error, data => {
if (error) {
callback(error)
} else {
callback(data)
}
})
)
}

// Add new show to watched list.
let addShowToWatchedList = (userID, newShow, cb) => {
let addShowToWatchedList = (userID, newShow, callback) => {
User.findOneAndUpdate(
{
_id: userID
Expand All @@ -205,18 +221,18 @@ let addShowToWatchedList = (userID, newShow, cb) => {
'shows_list.watched_list': newShow
}
},
(err, data) => {
if (err) {
cb(err);
(error, data) => {
if (error) {
callback(error);
} else {
cb(data);
callback(data);
}
}
);
};

// Delete show from watched list.
let deleteShowFromWatchedList = (userID, showID, cb) => {
let deleteShowFromWatchedList = (userID, showID, callback) => {
User.update(
{
_id: userID
Expand All @@ -227,7 +243,14 @@ let deleteShowFromWatchedList = (userID, showID, cb) => {
_id: showID
}
}
})
},
(error, data => {
if (error) {
callback(error)
} else {
callback(data)
}
}))
}

// Exporting Methods.
Expand Down
1 change: 1 addition & 0 deletions routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ router.post("/signup", authController.signUp);
// Logout.
router.post("/logout", authController.logout)

// Export The Router.
module.exports = router;
8 changes: 4 additions & 4 deletions routes/userRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ const userController = require("../controllers/UsersController")
router.patch("/movie/add/watchlist/:userID", userController.addMovieToWatchList);
// @DELETE
// Remove movie from watch list.
router.delete("/movie/delete/watchlist/:userID/:movieID", userController.deleteMovieFromWatchList);
router.patch("/movie/delete/watchlist/:userID/:movieID", userController.deleteMovieFromWatchList);
// @PUT
// Add movie to watched list.
router.patch("/movie/add/watchedlist/:userID", userController.addMovieToWatchedList);
// @DELETE
// Remove movie from watched list.
router.delete("/movie/delete/watchedlist/:userID/:movieID", userController.deleteMovieFromWatchedList);
router.patch("/movie/delete/watchedlist/:userID/:movieID", userController.deleteMovieFromWatchedList);

// TV SHOW ROUTES. **************************************************************
// @PUT
// Add TvShow to watch list.
router.patch("/show/add/watchlist/:userID", userController.addShowToWatchList);
// @DELETE
// Remove TvShow from watch list.
router.delete("/show/delete/watchlist/:userID/:showID", userController.deleteShowFromWatchList);
router.patch("/show/delete/watchlist/:userID/:showID", userController.deleteShowFromWatchList);
// @PUT
// Add TvShow to watched list.
router.patch("/show/add/watchedlist/:userID", userController.addShowToWatchedList);
// @DELETE
// Remove TvShow from watched list.
router.delete("/show/add/watchedlist/:userID/:showID", userController.deleteShowFromWatchedList);
router.patch("/show/add/watchedlist/:userID/:showID", userController.deleteShowFromWatchedList);

module.exports = router;

0 comments on commit bf0ea61

Please sign in to comment.