コード例 #1
0
def create_admin():
    """
    Endpoint to create admin user
    """
    super_user = request.headers.get('user_name')
    super_user_password = request.headers.get('password')
    if authenticate.authentic_user(super_user, super_user_password):
        user = request.values.get('admin_name')
        access_token = create_access_token({"user_name": user, "admin": True},
                                           expires_delta=datetime.timedelta(days=365))
        response_body = services.get_response_body(api_key=access_token)
        return Response(response_body, status=200, mimetype='application/json')
    response_body = services.get_response_body(err_msg="Invalid Credential")
    return Response(response_body, status=422, mimetype='application/json')
コード例 #2
0
def add_movie_endpoint():
    """
    Endpoint to add new movie entry
    """
    add_movie_scheme = schema_check.AddMovieInputScheme()
    errors = add_movie_scheme.validate(request.json)
    if errors:
        return Response(str(errors), status=422, mimetype='application/json')
    user_data = get_jwt_identity()
    if not user_data.get('admin'):
        response_body = services.get_response_body(msg="Unauthorized access")
        return Response(response_body, status=401, mimetype='application/json')
    movie_data = request.json.get('movie_data')
    resp_status, resp_msg = services.insert_movie(movie_data)
    response_body = services.get_response_body(msg=resp_msg)
    return Response(response_body, status=resp_status, mimetype='application/json')
コード例 #3
0
def remove_movie_endpoint():
    """
    Endpoint to delete movie entry for db
    """
    remove_movie_scheme = schema_check.RemoveMovieInputScheme()
    errors = remove_movie_scheme.validate(request.json)
    if errors:
        return Response(str(errors), status=422, mimetype='application/json')
    user_data = get_jwt_identity()
    if not user_data.get('admin'):
        response_body = services.get_response_body(msg="Unauthorized access")
        return Response(response_body, status=401, mimetype='application/json')
    movie_name = request.json.get('movie_name')
    resp_status, resp_msg = services.delete_movie(movie_name)
    response_body = services.get_response_body(msg=resp_msg)
    return Response(response_body, status=resp_status, mimetype='application/json')
コード例 #4
0
ファイル: app.py プロジェクト: neerajshukla1911/imdb
def remove_movie_endpoint():
    """
    Endpoint to delete movie entry for db
    """
    user_data = get_jwt_identity()
    if not user_data.get('admin'):
        response_body = services.get_response_body(msg="Unauthorized access")
        return Response(response_body, status=401, mimetype='application/json')
    movie_name = request.values.get('movie_name')
    if not movie_name:
        response_body = services.get_response_body(msg="Invalid entry")
        return Response(response_body, status=422, mimetype='application/json')
    resp_status, resp_msg = services.delete_movie(movie_name)
    response_body = services.get_response_body(msg=resp_msg)
    return Response(response_body,
                    status=resp_status,
                    mimetype='application/json')
コード例 #5
0
ファイル: app.py プロジェクト: neerajshukla1911/imdb
def add_movie_endpoint():
    """
    Endpoint to add new movie entry
    """
    user_data = get_jwt_identity()
    if not user_data.get('admin'):
        response_body = services.get_response_body(msg="Unauthorized access")
        return Response(response_body, status=401, mimetype='application/json')
    movie_data = request.values.get('movie_data')
    if not movie_data:
        response_body = services.get_response_body(msg="Invalid entry")
        return Response(response_body, status=422, mimetype='application/json')
    movie_data = json.loads(movie_data)
    resp_status, resp_msg = services.insert_movie(movie_data)
    response_body = services.get_response_body(msg=resp_msg)
    return Response(response_body,
                    status=resp_status,
                    mimetype='application/json')
コード例 #6
0
ファイル: app.py プロジェクト: neerajshukla1911/imdb
def search_movie():
    """
    Endpoint to search movie
    """
    movie_name = request.values.get('movie_name')
    if not movie_name:
        response_body = services.get_response_body(msg="Invalid entry")
        return Response(response_body, status=422, mimetype='application/json')
    movie_data = services.get_movie_data(movie_name)
    return Response(json.dumps(movie_data),
                    status=200,
                    mimetype='application/json')
コード例 #7
0
def create_user():
    """
    Endpoint to create user
    """
    user = request.json.get('user_name')
    create_user_schema = schema_check.CreateUserInputSchema()
    errors = create_user_schema.validate(request.json)
    if errors:
        return Response(str(errors), status=422, mimetype='application/json')
    access_token = create_access_token({"user_name": user, "admin": False},
                                       expires_delta=datetime.timedelta(hours=2))
    response_body = services.get_response_body(api_key=access_token)
    return Response(response_body, status=200, mimetype='application/json')
コード例 #8
0
ファイル: app.py プロジェクト: neerajshukla1911/imdb
def create_user():
    """
    Endpoint to create user
    """
    user = request.values.get('user_name')
    access_token = create_access_token(
        {
            "user_name": user,
            "admin": False
        },
        expires_delta=datetime.timedelta(hours=2))
    response_body = services.get_response_body(api_key=access_token)
    return Response(response_body, status=200, mimetype='application/json')