/**
 * Created by fran lopez on 8/12/15.
 */

    /**
     * AngularJS controller for film reviews AngularJS module. This
     * controller should be able to provide you with all the methods
     * needed to perform CRU operations.
     */

    angular.module('filmReviews').controller('FilmReviewsController',
        ['$scope', '$routeParams', '$location', 'FilmReviewsByFilmID',
            function ($scope, $routeParams, $location,
                      FilmReviewsByFilmID) {

                /**
                 * This method will retrieve a list of film reviews based
                 * on the "filmId" route parameter, which the function
                 * obtains directly from the URL.
                 *
                 * "filmId" route parameter stores information of
                 * an identifier associated to a film saved in database.
                 *
                 * The "filmID" parameter is used to include in the
                 * view scope, to return to the preview view. Furthermore,
                 * the parameter is used to call a AngularJS service,
                 * which provides information of film reviews associated
                 * to a film related to the parameter.
                 *
                 * This method use a HTTP GET request to execute the
                 * operation.
                 */

                $scope.find = function() {

                    $scope.filmId       = $routeParams.filmId;
                    $scope.filmReviews   = FilmReviewsByFilmID.query({
                        filmId: $routeParams.filmId
                    });
                };
            }
        ]
    );