Beispiel #1
0
def handler(event, context):
    try:
        global ev
        ev = event
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            params = event["queryStringParameters"]
            if params != None and "char_id" in params:
                return mysql_connector.success_response(
                    json.dumps(get_char(params["char_id"])))
            else:
                return mysql_connector.success_response(json.dumps(get_char()))
        elif httpMethod == "POST":
            try:
                data = json.loads(event["body"])
                if 'asset_id' in data:
                    return add_asset(event, data)
                elif 'camp_id' in data:
                    return add_campaign(event, data)
                else:
                    char_id = create_char(event, data)
                    return mysql_connector.success_response(
                        json.dumps(get_char(char_id)))
            except Exception as e:
                return mysql_connector.client_error("Invalid POST data" +
                                                    str(e))
        elif httpMethod == "PUT":
            try:
                data = json.loads(event["body"])
                update_char(event, data)
                return mysql_connector.success_response(
                    json.dumps(get_char(data["char_id"])))
            except Exception as e:
                return mysql_connector.client_error("Invalid PUT data" +
                                                    str(e))
        elif httpMethod == "DELETE":
            try:
                params = event["queryStringParameters"]
                if 'asset_id' in params:
                    return remove_asset(params)
                elif 'camp_id' in params:
                    return remove_campaign(params)
                else:
                    delete_char(params["char_id"])
                    return mysql_connector.success_response_string()
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except Exception as e:
        return mysql_connector.server_error("Unknown server error: " + str(e))
def handler(event, context):
    try:
        global ev
        ev = event
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            params = event["queryStringParameters"]
            if params != None and "camp_id" in params:
                camp_id = params["camp_id"]
                return mysql_connector.success_response(
                    json.dumps(get_users(camp_id)))
            else:
                return mysql_connector.success_response(
                    json.dumps(get_invites()))
        elif httpMethod == "POST":
            try:
                data = json.loads(event["body"])
                create_invite(data)
                return mysql_connector.success_response_string()
            except Exception as e:
                return mysql_connector.client_error("Invalid POST data" +
                                                    str(e))
        elif httpMethod == "PUT":
            try:
                data = json.loads(event["body"])
                update_invite(data)
                return mysql_connector.success_response_string()
            except Exception as e:
                return mysql_connector.client_error("Invalid PUT data" +
                                                    str(e))
        elif httpMethod == "DELETE":
            try:
                params = event["queryStringParameters"]
                delete_invite(params["camp_id"])
                return mysql_connector.success_response_string()
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except Exception as e:
        return mysql_connector.server_error("Unknown server error " + str(e))
def handler(event, context):
    try:
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            q = """ 
                select 
                    set_id,
                    set_name,
                    set_desc,
                    created_by
                from value_sets
                """

            params = event["queryStringParameters"]
            if params != None and "set_name" in params:
                q += " where set_name = %s"
                params = (params["set_name"])
                return mysql_connector.single_query(q, params)

            return mysql_connector.query(q, params)
        elif httpMethod == "POST":
            try:
                sql = """
                    INSERT INTO value_sets (
                        set_name,
                        set_desc,
                        created_by,
                        created_date,
                        updated_by,
                        updated_date
                    ) VALUES (
                        %s,
                        %s,
                        %s,
                        SYSDATE(),
                        %s,
                        SYSDATE());
                    """

                data = json.loads(event["body"])
                params = (data.get("set_name", ""), data.get("set_desc", ""),
                          mysql_connector.get_username(event),
                          mysql_connector.get_username(event))
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid POST data")
        elif httpMethod == "PUT":
            try:
                sql = """
                    UPDATE value_sets
                    SET set_name = %s,
                        set_desc = %s,
                        updated_by = %s,
                        updated_date = SYSDATE()
                    WHERE set_id = %s
                    """

                data = json.loads(event["body"])
                params = (data.get("set_name", ""), data.get("set_desc", ""),
                          mysql_connector.get_username(event),
                          data.get("set_id", ""))
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid PUT data")
        elif httpMethod == "DELETE":
            try:
                sql = """
                    DELETE FROM value_sets
                    WHERE set_id = %s
                    """

                data = json.loads(event["body"])
                params = (data.get("set_id", ""))
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except:
        return mysql_connector.server_error("Unknown server error")
Beispiel #4
0
def handler(event, context):
    q = """ 
        select
            armor_id,
            armor_name,
            armor_desc,
            armor_type,
            cost,
            armor_class,
            strength,
            IF(stealth_dis, 'true', 'false') stealth_dis,
            weight,
            created_by
        from armor
        where 1=1 
        """

    try:
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            params = event["queryStringParameters"]
            if params != None and "armor_id" in params:
                q += " and armor_id = %s"
                params = (params["armor_id"])
                return mysql_connector.single_query(q, params)
            else:
                return mysql_connector.query(q, params)
        elif httpMethod == "POST":
            try:
                sql = """
                    INSERT INTO armor (
                        armor_name,
                        armor_desc,
                        armor_type,
                        cost,
                        armor_class,
                        strength,
                        stealth_dis,
                        weight,
                        created_by,
                        created_date,
                        updated_by,
                        updated_date
                    ) VALUES (
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        SYSDATE(),
                        %s,
                        SYSDATE());
                    """

                data = json.loads(event["body"])
                params = (data.get("armor_name",
                                   ""), data.get("armor_desc", ""),
                          data.get("armor_type", ""), data.get("cost", ""),
                          data.get("armor_class",
                                   ""), data.get("strength", ""),
                          (1 if str(data.get("stealth_dis", "")).lower()
                           == "true" else 0), data.get("weight", ""),
                          mysql_connector.get_username(event),
                          mysql_connector.get_username(event))
                mysql_connector.execute(sql, params)

                q += """ and armor_id = LAST_INSERT_ID()"""
                return mysql_connector.single_query(q)
            except:
                return mysql_connector.client_error("Invalid POST data")
        elif httpMethod == "PUT":
            try:
                sql = """
                    UPDATE armor
                    SET armor_name = %s,
                        armor_desc = %s,
                        armor_type = %s,
                        cost = %s,
                        armor_class = %s,
                        strength = %s,
                        stealth_dis = %s,
                        weight = %s,
                        updated_by = %s,
                        updated_date = SYSDATE()
                    WHERE armor_id = %s
                    """

                data = json.loads(event["body"])
                params = (data.get("armor_name",
                                   ""), data.get("armor_desc", ""),
                          data.get("armor_type", ""), data.get("cost", ""),
                          data.get("armor_class",
                                   ""), data.get("strength", ""),
                          (1 if str(data.get("stealth_dis", "")).lower()
                           == "true" else 0), data.get("weight", ""),
                          mysql_connector.get_username(event),
                          data.get("armor_id", ""))
                mysql_connector.execute(sql, params)

                params = (data.get("armor_id", ""))
                q += """ and armor_id = %s"""
                return mysql_connector.single_query(q, params)
            except:
                return mysql_connector.client_error("Invalid PUT data")
        elif httpMethod == "DELETE":
            try:
                sql = """
                    DELETE FROM armor
                    WHERE armor_id = %s
                    """

                params = event["queryStringParameters"]
                params = (params["armor_id"])
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except:
        return mysql_connector.server_error("Unknown server error")
def handler(event, context):
    q = """ 
        select
            weapon_id,
            weapon_name,
            weapon_desc,
            weapon_type,
            cost,
            damage,
            weight,
            weapon_props,
            created_by
        from weapons
        where 1=1 
        """

    try:
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            params = event["queryStringParameters"]
            if params != None and "weapon_id" in params:
                q += " and weapon_id = %s"
                params = (params["weapon_id"])
                return mysql_connector.single_query(q, params)
            else:
                return mysql_connector.query(q, params)
        elif httpMethod == "POST":
            try:
                sql = """
                    INSERT INTO weapons (
                        weapon_name,
                        weapon_desc,
                        weapon_type,
                        cost,
                        damage,
                        weight,
                        weapon_props,
                        created_by,
                        created_date,
                        updated_by,
                        updated_date
                    ) VALUES (
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        SYSDATE(),
                        %s,
                        SYSDATE());
                    """

                data = json.loads(event["body"])
                params = (data.get("weapon_name",
                                   ""), data.get("weapon_desc", ""),
                          data.get("weapon_type", ""), data.get("cost", ""),
                          data.get("damage", ""), data.get("weight", ""),
                          data.get("weapon_props",
                                   ""), mysql_connector.get_username(event),
                          mysql_connector.get_username(event))
                mysql_connector.execute(sql, params)

                q += """ and weapon_id = LAST_INSERT_ID()"""
                return mysql_connector.single_query(q)
            except:
                return mysql_connector.client_error("Invalid POST data")
        elif httpMethod == "PUT":
            try:
                sql = """
                    UPDATE weapons
                    SET weapon_name = %s,
                        weapon_desc = %s,
                        weapon_type = %s,
                        cost = %s,
                        damage = %s,
                        weight = %s,
                        weapon_props = %s,
                        updated_by = %s,
                        updated_date = SYSDATE()
                    WHERE weapon_id = %s
                    """

                data = json.loads(event["body"])
                params = (data.get("weapon_name",
                                   ""), data.get("weapon_desc", ""),
                          data.get("weapon_type", ""), data.get("cost", ""),
                          data.get("damage", ""), data.get("weight", ""),
                          data.get("weapon_props",
                                   ""), mysql_connector.get_username(event),
                          data.get("weapon_id", ""))
                mysql_connector.execute(sql, params)

                params = (data.get("weapon_id", ""))
                q += """ and weapon_id = %s"""
                return mysql_connector.single_query(q, params)
            except:
                return mysql_connector.client_error("Invalid PUT data")
        elif httpMethod == "DELETE":
            try:
                sql = """
                    DELETE FROM weapons
                    WHERE weapon_id = %s
                    """

                params = event["queryStringParameters"]
                params = (params["weapon_id"])
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except:
        return mysql_connector.server_error("Unknown server error")
def handler(event, context):
    q = """ 
        select 
            sv.value_id,
            sv.set_value,
            sv.value_desc,
            sv.created_by,
            vs.set_id,
            vs.set_name
        from set_values sv,
                value_sets vs
        where 
            sv.set_id = vs.set_id 
        """

    try:
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            params = event["queryStringParameters"]
            if params != None and "set_name" in params:
                q += " and vs.set_name = %s"
                params = (params["set_name"])

            return mysql_connector.query(q, params)
        elif httpMethod == "POST":
            try:
                sql = """
                    INSERT INTO set_values (
                        set_value,
                        set_id,
                        value_desc,
                        created_by,
                        created_date,
                        updated_by,
                        updated_date
                    ) VALUES (
                        %s,
                        (SELECT vs.set_id FROM value_sets vs WHERE vs.set_name = %s),
                        %s,
                        %s,
                        SYSDATE(),
                        %s,
                        SYSDATE());
                    """
                data = json.loads(event["body"])
                params = (data.get("set_value", ""), data.get("set_name", ""),
                          data.get("value_desc",
                                   ""), mysql_connector.get_username(event),
                          mysql_connector.get_username(event))
                mysql_connector.execute(sql, params)

                q += """ and sv.value_id = LAST_INSERT_ID()"""
                return mysql_connector.single_query(q)
            except Exception as e:
                return mysql_connector.client_error("Invalid POST data" +
                                                    str(e))
        elif httpMethod == "PUT":
            try:
                sql = """
                    UPDATE set_values
                    SET set_value = %s,
                        value_desc = %s,
                        updated_by = %s,
                        updated_date = SYSDATE()
                    WHERE value_id = %s
                    """

                data = json.loads(event["body"])
                params = (data.get("set_value",
                                   ""), data.get("value_desc", ""),
                          mysql_connector.get_username(event),
                          data.get("value_id", ""))
                mysql_connector.execute(sql, params)

                params = (data.get("value_id", ""))
                q += """ and sv.value_id = %s"""
                return mysql_connector.single_query(q, params)
            except:
                return mysql_connector.client_error("Invalid PUT data")
        elif httpMethod == "DELETE":
            try:
                sql = """
                    DELETE FROM set_values
                    WHERE value_id = %s
                    """

                params = event["queryStringParameters"]
                params = (params["value_id"])
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except:
        return mysql_connector.server_error("Unknown server error")
Beispiel #7
0
def handler(event, context):
    q = """ 
        select
            spell_id,
            spell_name,
            spell_desc,
            spell_level,
            higher_level,
            spell_range,
            components,
            IF(ritual, 'true', 'false') ritual,
            duration,
            casting_time,
            spell_school,
            created_by
        from spells
        where 1=1 
        """

    try:
        httpMethod = event["httpMethod"]

        if httpMethod == "GET":
            params = event["queryStringParameters"]
            if params != None and "spell_id" in params:
                q += " and spell_id = %s"
                params = (params["spell_id"])
                return mysql_connector.single_query(q, params)
            else:
                return mysql_connector.query(q, params)
        elif httpMethod == "POST":
            try:
                sql = """
                    INSERT INTO spells (
                        spell_name,
                        spell_desc,
                        spell_level,
                        higher_level,
                        spell_range,
                        components,
                        ritual,
                        duration,
                        casting_time,
                        spell_school,
                        created_by,
                        created_date,
                        updated_by,
                        updated_date
                    ) VALUES (
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        %s,
                        SYSDATE(),
                        %s,
                        SYSDATE());
                    """

                data = json.loads(event["body"])
                params = (data.get("spell_name",
                                   ""), data.get("spell_desc", ""),
                          data.get("spell_level",
                                   ""), data.get("higher_level", ""),
                          data.get("spell_range",
                                   ""), data.get("components", ""),
                          (1 if str(data.get("ritual", "")).lower() == "true"
                           else 0), data.get("duration",
                                             ""), data.get("casting_time", ""),
                          data.get("spell_school",
                                   ""), mysql_connector.get_username(event),
                          mysql_connector.get_username(event))
                mysql_connector.execute(sql, params)

                q += """ and spell_id = LAST_INSERT_ID()"""
                return mysql_connector.single_query(q)
            except:
                return mysql_connector.client_error("Invalid POST data")
        elif httpMethod == "PUT":
            try:
                sql = """
                    UPDATE spells
                    SET spell_name = %s,
                        spell_desc = %s,
                        spell_level = %s,
                        higher_level = %s,
                        spell_range = %s,
                        components = %s,
                        ritual = %s,
                        duration = %s,
                        casting_time = %s,
                        spell_school = %s,
                        updated_by = %s,
                        updated_date = SYSDATE()
                    WHERE spell_id = %s
                    """

                data = json.loads(event["body"])
                params = (data.get("spell_name",
                                   ""), data.get("spell_desc", ""),
                          data.get("spell_level",
                                   ""), data.get("higher_level", ""),
                          data.get("spell_range",
                                   ""), data.get("components", ""),
                          (1 if str(data.get("ritual", "")).lower() == "true"
                           else 0), data.get("duration",
                                             ""), data.get("casting_time", ""),
                          data.get("spell_school",
                                   ""), mysql_connector.get_username(event),
                          data.get("spell_id", ""))
                mysql_connector.execute(sql, params)

                params = (data.get("spell_id", ""))
                q += """ and spell_id = %s"""
                return mysql_connector.single_query(q, params)
            except:
                return mysql_connector.client_error("Invalid PUT data")
        elif httpMethod == "DELETE":
            try:
                sql = """
                    DELETE FROM spells
                    WHERE spell_id = %s
                    """

                params = event["queryStringParameters"]
                params = (params["spell_id"])
                return mysql_connector.execute(sql, params)
            except:
                return mysql_connector.client_error("Invalid DELETE data")
        else:
            return mysql_connector.client_error("Invalid HTTP Method")
    except:
        return mysql_connector.server_error("Unknown server error")