Exemplo n.º 1
0
    def create_movie(jwt):
        body = request.json
        title = body.get('title', None)
        release_date = body.get('release_date', None)

        # Abort 400 if the title in the request matches any of the saved movie titles
        if title in list(map(Movies.get_title, Movies.query.all())):
            abort(
                400,
                'This title is already taken. Please provide a new title and try again.'
            )

        # Abort 400 if any fields are missing
        if any(arg is None for arg in [title, release_date]) or '' in [
                title, release_date
        ]:
            abort(400, 'title and release_date are required fields.')

        # Create and insert a new movie
        new_movie = Movies(title=title, release_date=release_date)
        new_movie.insert()

        # Return the newly created movie
        return jsonify({
            'success': True,
            'movies': [Movies.query.get(new_movie.id).format()]
        })
Exemplo n.º 2
0
    def setUp(self):
        self.app = app
        self.client = app.test_client

        setup_db(app, database_path, True)

        self.new_movie = {"id": "12dsa3", "title": "test"}

        movie = Movies(id=self.new_movie['id'], title=self.new_movie['title'])
        movie.insert()
Exemplo n.º 3
0
 def create_movies(jwt):
     title = request.get_json()['title']
     release_date = request.get_json()['release_date']
     img_link = request.get_json()['img_link']
     movie = Movies(title=title,
                    release_date=parse(release_date),
                    img_link=img_link)
     if movie:
         movie.insert()
         result = {"success": "True", "movies": movie.format()}
         return jsonify(result)
     else:
         abort(404)
Exemplo n.º 4
0
 def movie_delete(payload, movie_id):
     error = False
     try:
         get_movie = Movies.query.filter_by(id=movie_id).first()
         Movies.delete(get_movie)
     except:
         error = True
         print(sys.exc_info())
     finally:
         if error:
             abort(404)
         else:
             return jsonify({'success': True, "id": get_movie.id})
Exemplo n.º 5
0
 def create_movie(payload):
     error = False
     title = request.get_json()['title']
     release_date = request.get_json()['releaseDate']
     try:
         added_movie = Movies(title=title, release_date=release_date)
         Movies.insert(added_movie)
     except (TypeError, ValueError, KeyError):
         error = True
         print(sys.exc_info())
     finally:
         if error:
             abort(422)
         else:
             return jsonify({'success': True})
Exemplo n.º 6
0
def addMoviePrivate(payload):
    # Get the api key

    id = request.get_json()

    # Request the omdbapi api
    data = requests.get(
        f'http://www.omdbapi.com/?apikey={apiKey}&i={id}&plot=full')

    # Convert the result to json
    d = data.json()

    if d['Response'] == 'False':
        return jsonify({
            'success': False,
            'msg': 'Movie with this title  not found!',
        }), 400

    userID = payload['sub']
    try:

        # Insert to database
        movie = Movies(imdbID=d['imdbID'],
                       userID=userID,
                       Title=d['Title'],
                       Genre=d['Genre'],
                       Director=d['Director'],
                       Poster=d['Poster'],
                       imdbRating=d['imdbRating'],
                       Runtime=d['Runtime'],
                       Plot=d['Plot'],
                       Released=d['Released'],
                       Awards=d['Awards'],
                       Language=d['Language'],
                       Actors=d['Actors'],
                       Writer=d['Writer'])
        movie.insert()

    except:
        return jsonify({
            'success': False,
            'msg': 'This movie exist in the private hub',
        }), 400

    return jsonify({
        'success': True,
        'msg': 'Movie has been added to the private hub'
    }), 200
Exemplo n.º 7
0
def create_movies(*args, **kwargs):
    try:
        body = request.get_json()
        new_title = body.get('title')
        new_releasedate = body.get('releasedate')

        movies = Movies(title=new_title, releasedate=new_releasedate)
        movies.insert()

        return jsonify({
            "success": True,
            "message": "Movie Successfully Added!",
            "movies": movies.format()
        })

    except AttributeError:
        abort(422)
Exemplo n.º 8
0
def addMoviePublic(payload):
    # Get the api key

    id = request.get_json()

    # Check if permissions array in the JWT
    if 'permissions' not in payload:
        return jsonify({
            'success':
            False,
            'msg':
            'Sorry only selected users can add movies to the public hub',
        }), 401

    # Check if the user have permissions to accsses this rescuers
    if 'post:public' not in payload['permissions']:
        return jsonify({
            'success':
            False,
            'msg':
            'Sorry only selected users can add movies to the public hub',
        }), 401

    # Request the omdbapi api
    data = requests.get(
        f'http://www.omdbapi.com/?apikey={apiKey}&i={id}&plot=full')

    # Convert the result to json
    d = data.json()

    if d['Response'] == 'False':
        return jsonify({
            'success': False,
            'msg': 'Movie with this title  not found!',
        }), 400

    userID = 'public'
    try:

        # Insert to database
        movie = Movies(imdbID=d['imdbID'],
                       userID=userID,
                       Title=d['Title'],
                       Genre=d['Genre'],
                       Director=d['Director'],
                       Poster=d['Poster'],
                       imdbRating=d['imdbRating'],
                       Runtime=d['Runtime'],
                       Plot=d['Plot'],
                       Released=d['Released'],
                       Awards=d['Awards'],
                       Language=d['Language'],
                       Actors=d['Actors'],
                       Writer=d['Writer'])
        movie.insert()

    except:
        return jsonify({
            'success': False,
            'msg': 'This movie exist in the public hub',
        }), 400

    return jsonify({
        'success': True,
        'msg': 'Movie has been added to the public hub'
    }), 200