Skip to content

Commit

Permalink
added trailer to detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
dev92 committed Mar 26, 2016
1 parent 0b08273 commit 15edf6f
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 23 deletions.
25 changes: 23 additions & 2 deletions public/project/client/services/movie.services.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

var api = {
userLikesMovie: userLikesMovie,
findUserLikes: findUserLikes
findUserLikes: findUserLikes,
findUserLikedMovies:findUserLikedMovies,
userDislikesMovie:userDislikesMovie
};
return api;

function findUserLikes (imdbID) {
var defer = $q.defer();
console.log(imdbID);
var url = "/api/project/movie/"+imdbID+"/user";
$http.get(url)
.success(function(response){
Expand All @@ -32,5 +33,25 @@
});
return defer.promise;
}

function findUserLikedMovies(userId,movieIds){
var defer = $q.defer();
var url = "/api/project/user/"+userId+"/movies";
$http.get(url,movieIds)
.success(function(response){
defer.resolve(response);
});
return defer.promise;
}

function userDislikesMovie(userId,imdbId){
var defer = $q.defer();
var url = "/api/project/user/"+userId+"/movie/"+imdbId;
$http.delete(url)
.success(function(response){
defer.resolve(response);
});
return defer.promise;
}
}
})();
11 changes: 9 additions & 2 deletions public/project/client/services/movieapi.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
var searchUrl = "http://api.themoviedb.org/3/search/movie?query=QUERY&api_key=c8fee912d3f3866df68026f0ebadc6f6";
var genreMovies = "http://api.themoviedb.org/3/genre/GENRE/movies?api_key=c8fee912d3f3866df68026f0ebadc6f6";
var detailsUrl = "http://api.themoviedb.org/3/movie/ID?api_key=c8fee912d3f3866df68026f0ebadc6f6";
var imdbdetailsUrl = "https://api.themoviedb.org/3/find/IMDBID?external_source=imdb_id&api_key=c8fee912d3f3866df68026f0ebadc6f6"
var imdbdetailsUrl = "https://api.themoviedb.org/3/find/IMDBID?external_source=imdb_id&api_key=c8fee912d3f3866df68026f0ebadc6f6";
var trailerUrl = "http://api.themoviedb.org/3/movie/ID/videos?api_key=c8fee912d3f3866df68026f0ebadc6f6";



var api = {
findMovieByTitle : findMovieByTitle,
findMovieByImdbID:findMovieByImdbID,
findBasePath:findBasePath
findBasePath:findBasePath,
findTrailers:findTrailers
};

return api;
Expand All @@ -43,5 +45,10 @@
.success(callback);
}

function findTrailers(tmdbId,callback){
$http.get(trailerUrl.replace("ID",tmdbId))
.success(callback);
}

}
})();
22 changes: 17 additions & 5 deletions public/project/client/views/myspace/favorites.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
.module("CinephiliaApp")
.controller("FavoritesController", FavoritesController);

function FavoritesController($scope) {
function FavoritesController($scope,$rootScope,MovieService) {

$scope.movies = [];

if($rootScope.currentusr){
MovieService.findUserLikedMovies($rootScope.currentusr._id)
.then(function(response){
$scope.movies = response;
});
}

$scope.removeFavorite = function(imdbId){
MovieService.userDislikesMovie($rootScope.currentusr._id,imdbId)
.then(function(response){
$scope.movies = response;
})
}

$scope.movies = [{Title:"Batman",imdbID:"tt0096895",poster:"https://i.ytimg.com/vi/A0f3vH3BNvc/maxresdefault.jpg",
favorite:true},{Title:"Avatar",imdbID:"tt0499549",poster:"http://t0.gstatic.com/images?q=tbn:ANd9GcQCfmvrE4fMo2cd8esc7mDZPtFSJThAujddMPkRtti1_ij6u-jp",
favorite:true},{Title:"12 Angry men",imdbID:"tt0050083",poster:"http://t0.gstatic.com/images?q=tbn:ANd9GcTDnld_1CpP-iESMfN_iAF0yEOYAhv0gX7F3RKIf47oQIua_vAS",
favorite:true}]
}
})();
4 changes: 2 additions & 2 deletions public/project/client/views/myspace/favorites.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</md-tab>
</md-tabs>
</md-content>
<div class="well" style="background-color: rgba(96, 125, 139, 0.7)" ng-controller="FavoritesController">
<div class="well" style="background-color: rgba(96, 125, 139, 0.7)">
<div class="md-padding" layout="row" layout-xs="column" layout-align="center center" flex="33" layout-wrap>
<md-card ng-repeat="movie in movies">
<md-card-title>
Expand All @@ -23,7 +23,7 @@
<img class = "img-responsive" style="height: 300px;width: 300px;display: block;margin: 0 auto" ng-src="{{movie.poster}}" onerror="this.src='http://www.filmfodder.com/reviews/images/poster-not-available.jpg'" class="md-card-image" alt="Washed Out">
<md-card-actions layout="row" layout-align="center center">
<md-button class="md-icon-button" aria-label="Favorite">
<md-icon ng-click="movie.favorite = !movie.favorite" class="md-icon-button md-accent"><i ng-class="{'fa fa-heart-o fa-lg':!movie.favorite,'fa fa-heart fa-lg':movie.favorite}"></i></md-icon>
<md-icon ng-click="removeFavorite(movie.imdbID)" class="md-icon-button md-accent"><i class="fa fa-heart fa-lg"></i></md-icon>
</md-button>
<md-button class="md-icon-button" aria-label="Details">
<md-icon><a href="#/detail/{{movie.imdbID}}"><i class="fa fa-info-circle fa-lg"></i></a></md-icon>
Expand Down
4 changes: 2 additions & 2 deletions public/project/client/views/myspace/reviews.view.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div id="page-wrapper">
<!--<div class="container-fluid">-->
<div class="container-fluid">
<!--<div class="row">-->
<div class="col-md-10 col-md-offset-2 main">
<md-content>
Expand Down Expand Up @@ -29,5 +29,5 @@
</div>
<!--</div>-->
</div>
<!--</div>-->
</div>
</div>
10 changes: 9 additions & 1 deletion public/project/client/views/search/details.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.module("CinephiliaApp")
.controller("DetailController", DetailController);

function DetailController($scope, $rootScope, $routeParams, MovieApiService,MovieService) {
function DetailController($scope, $rootScope, $routeParams, MovieApiService,MovieService,$sce) {

$scope.imdbID = $routeParams.imdbID;
$scope.users = [];
Expand All @@ -26,6 +26,14 @@
//console.log(response.imdbID);
$scope.rating = Number(response.imdbRating).toFixed();
$scope.movie = response;
MovieApiService.findTrailers($scope.imdbID,function(response){
for(var r in response.results){
if(response.results[r].type == "Trailer"){
$scope.movie.trailer = $sce.trustAsResourceUrl("http://www.youtube.com/v/"+response.results[r].key);
}
}
});

MovieService.findUserLikes($scope.movie.imdbID)
.then(function(response){
$scope.users = response;
Expand Down
6 changes: 6 additions & 0 deletions public/project/client/views/search/details.view.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ <h4>Release Year:<p>{{movie.Released}}</p></h4>
<h4>Rated:<p>{{movie.Rated}}</p></h4>
</div>
</div>
<div class="row">
<h4 style="text-align: center">Trailer</h4>
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" controls="true" frameborder="0" src="{{movie.trailer}}" allowfullscreen="true"></iframe>
</div>
</div>
<hr>
<div class="row" style="padding-left: 40px">
<div class="col-md-6">
Expand Down
14 changes: 13 additions & 1 deletion public/project/server/models/movie.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = function() {
findMovieByImdbID: findMovieByImdbID,
findMoviesByImdbIDs: findMoviesByImdbIDs,
createMovie: createMovie,
userLikesMovie: userLikesMovie
userLikesMovie: userLikesMovie,
userDislikesMovie:userDislikesMovie
};
return api;

Expand Down Expand Up @@ -47,5 +48,16 @@ module.exports = function() {
return movies[i];
}
}
return null;
}

function userDislikesMovie(userId,imdbId){
var movie = findMovieByImdbID(imdbId);
for(var i in movie.userFavorites){
if(movie.userFavorites[i] == userId){
movie.userFavorites.splice(i,1)
return movie;
}
}
}
}
6 changes: 3 additions & 3 deletions public/project/server/models/movies.mock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
{"imdbID": "tt0050083", "tmdbID":389,"title": "12 Angry men", "userFavorites":[234]},
{"imdbID": "tt0096895", "tmdbID":268,"title":"Batman", "userFavorites":[123,345]},
{"imdbID": "tt0295297", "tmdbID":672,"title":"Harry Potter and the Chamber of Secrets","userFavorites":[234,456]}
{"imdbID": "tt0050083", "tmdbID":389,"title": "12 Angry men", "userFavorites":[234],"poster":"http://img.omdbapi.com/?i=tt0050083&apikey=2bf5ee9"},
{"imdbID": "tt0096895", "tmdbID":268,"title":"Batman", "userFavorites":[123,345],"poster":"http://img.omdbapi.com/?i=tt0096895&apikey=2bf5ee9"},
{"imdbID": "tt0295297", "tmdbID":672,"title":"Harry Potter and the Chamber of Secrets","userFavorites":[234,456],"poster":"http://img.omdbapi.com/?i=tt0295297&apikey=2bf5ee9"}
]
16 changes: 15 additions & 1 deletion public/project/server/models/user.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = function() {
findFriendsById: findFriendsById,
findUsersByIds: findUsersByIds,
userLikesMovie: userLikesMovie,
userDislikesMovie:userDislikesMovie,
deleteUserFriend:deleteUserFriend,
checkExistingUser:checkExistingUser
};
Expand Down Expand Up @@ -121,7 +122,7 @@ module.exports = function() {
for (var u in users[i].friends) {
if (users[i].friends[u] == friendId) {
users[i].friends.splice(u, 1);
return findUsersByIds(Update(userId, users[i])._id)
return findFriendsById(Update(userId, users[i])._id)
}
}
}
Expand All @@ -145,4 +146,17 @@ module.exports = function() {
}
}

function userDislikesMovie(userId,imdbId){
var user = FindById(userId);
if(user){
for(var m in user.favorites){
if(user.favorites[m] == imdbId){
user.favorites.splice(m,1);
return Update(userId,user);
}
}

}
}

}
22 changes: 21 additions & 1 deletion public/project/server/services/movie.service.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,38 @@ module.exports = function(app, movieModel, userModel) {


app.post("/api/project/user/:userId/movie/:imdbID", userLikesMovie);
app.delete("/api/project/user/:userId/movie/:imdbID", userDislikesMovie);
app.get("/api/project/movie/:imdbID/user", findUserLikes);
app.get("/api/project/user/:userId/movies", findUserLikedMovies);

function findUserLikes (req, res) {

var imdbID = req.params.imdbID;
var movie = movieModel.findMovieByImdbID(imdbID);
res.json(userModel.findUsersByIds(movie.userFavorites));
if(movie){
res.json(userModel.findUsersByIds(movie.userFavorites));
}else{
res.status(404).send(null);
}


}

function userLikesMovie(req, res) {
userModel.userLikesMovie(req.params.userId,req.params.imdbID)
res.json(movieModel.userLikesMovie(req.params.userId,req.params.imdbID))
}

function findUserLikedMovies(req, res){
var user = userModel.FindById(req.params.userId);
res.json(movieModel.findMoviesByImdbIDs(user.favorites));
}

function userDislikesMovie(req, res){
movieModel.userDislikesMovie(req.params.userId,req.params.imdbID);
var user = userModel.userDislikesMovie(req.params.userId,req.params.imdbID)
res.json(movieModel.findMoviesByImdbIDs(user.favorites));
}


}
6 changes: 3 additions & 3 deletions public/project/server/services/user.service.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = function(app, model) {

app.get("/api/project/user",FindUser);
app.get("/api/project/user/:id",FindById);
app.get("/api/project/user/:id/friends",findUsersByIds);
app.get("/api/project/user/:id/friends",FindFriendsById);
app.delete("/api/project/user/:id/friend/:friendId",DeleteUserFriend);
app.put("/api/project/user/:id",UpdateUser);
app.delete("/api/project/user/:id", DeleteUser);
Expand Down Expand Up @@ -59,9 +59,9 @@ module.exports = function(app, model) {

}

function findUsersByIds(req, res){
function FindFriendsById(req, res){

res.json(model.findUsersByIds(req.params.id));
res.json(model.findFriendsById(req.params.id));
}

function DeleteUserFriend(req, res){
Expand Down

0 comments on commit 15edf6f

Please sign in to comment.