Ejemplo n.º 1
0
def post_user_suggestion(request_data):
    try:
        user_name = request_data['user_name']
    except KeyError as _:
        raise BlankException(
            f'''There is no field [user_name] in the request body''')
    try:
        suggestion = request_data['suggestion']
    except KeyError as _:
        raise BlankException(
            f'''There is no field [suggestion] in the request body''')

    return insert('user_suggestions',
                  user_name=user_name,
                  suggestion=suggestion)
Ejemplo n.º 2
0
def get_team(name):
    if name is None:
        raise BlankException(f'''The parameter [name] is required''', 400)

    data = select('teams', 1, team_name=name)
    if len(data) == 0:
        raise BlankException(f'''There is no season for the team [{name}]''',
                             404)

    data = data[0]
    return {
        'name': data['team_name'],
        'state': data['state'],
        'division': data['division'],
        'conference': data['conference']
    }
Ejemplo n.º 3
0
def get_season(team):
    if team is None:
        raise BlankException(f'''The parameter [team] is required''', 400)

    data = select('season', 1, team_name=team)
    if len(data) == 0:
        raise BlankException(f'''There is no season for the team [{team}]''',
                             404)

    data = data[0]
    return {
        'name': data['team_name'],
        'wins': data['wins'],
        'losses': data['losses'],
        'ties': data['ties'],
        'playoffs': data['playoffs'],
        'superbowl_champ': data['superbowl_champ'],
    }
Ejemplo n.º 4
0
def convert_to_int(**kwargs):
    converted_args = []
    for (key, val) in kwargs.items():
        if key == 'limit' and val is None:
            converted_args.append(default_limit(val))
            continue
        if val is None:
            converted_args.append(None)
            continue
        try:
            converted_args.append(int(val))
        except ValueError as _:
            raise BlankException(
                f'''The arg [{key}] cannot be converted to an int''', code=400)
    return tuple(converted_args)
Ejemplo n.º 5
0
def executeQuery(query_string):
    print("QUERY:", query_string)
    try:
        open_db()
        cur = conn.cursor()
        cur.execute(query_string)
        conn.commit()
        if 'select' in query_string.lower():
            rows = cur.fetchall()
            data = build_dicts(cur, rows)
            cur.close()
            close_db()
            return data
        return 'Success'
    except (Exception, psycopg2.DatabaseError) as error:
        raise BlankException(error)
Ejemplo n.º 6
0
def delete_suggestion(suggestion_id):
    if suggestion_id is None:
        raise BlankException(f'''The parameter [id] is required''')
    suggestion_id = convert_to_int(id=suggestion_id)[0]
    return delete('user_suggestions', id=suggestion_id)