Exemple #1
0
def handler(event, context):

    # ["project_id"]
    required_args_present=False

    try:
        required_args_present = set(['user_id']).issubset(set(list(event["queryStringParameters"].keys())))
    except Exception as e:
        return {
        "statusCode" : "400" ,
        "headers" : {
            "Content-Type" : "application/json" ,
            "Access-Control-Allow-Headers" : 'Content-Type' ,
            "Access-Control-Allow-Origin" : "*" ,
            "Access-Control-Allow-Methods" : "POST, OPTIONS" ,
            "Access-Control-Allow-Credentials" : True
        },
        "body": json.dumps({"ERROR":"Error getting queryStringParameters of request, it may not have been passed correctly",
                            "Exception":str(e)})
        }

    if (not required_args_present):
        return {
        "statusCode" : "400" ,
        "headers" : {
            "Content-Type" : "application/json" ,
            "Access-Control-Allow-Headers" : 'Content-Type' ,
            "Access-Control-Allow-Origin" : "*" ,
            "Access-Control-Allow-Methods" : "POST, OPTIONS" ,
            "Access-Control-Allow-Credentials" : True
        },
        "body": json.dumps({"ERROR":"The required queryStringParameter [USER_ID] is not present"})
        }



    # all the args are present so can get
    user_id = event["queryStringParameters"]["user_id"]

    ddb = awsUtils.connect_ddb()
    response=ddb.Table('osu-expo-users').get_item(Key={'user_id':user_id})


    ret = {
        "statusCode" : "200" ,
        "headers" : {
            "Content-Type" : "application/json" ,
            "Access-Control-Allow-Headers" : 'Content-Type' ,
            "Access-Control-Allow-Origin" : "*" ,
            "Access-Control-Allow-Methods" : "POST, OPTIONS" ,
            "Access-Control-Allow-Credentials" : True
        },
        "body": json.dumps( response,default=default)}

    return ret
Exemple #2
0
def handler(event, context):

    ddb = awsUtils.connect_ddb()
    user_table = ddb.Table('osu-expo-users')
    table_data = user_table.scan()
    ret = {
        "statusCode": "200",
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Headers": 'Content-Type',
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "POST, OPTIONS",
            "Access-Control-Allow-Credentials": True
        },
        "body": json.dumps(table_data["Items"], default=default)
    }
    return ret
Exemple #3
0
def handler(event, context):

    required_args_present = False
    try:
        required_args_present = set([
            'name', 'description', 'picture', 'team', 'school', 'tech',
            'college', 'links', 'boothNumber'
        ]).issubset(set(list(json.loads(event["body"]).keys())))
    except Exception as e:
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps({
                "ERROR":
                "Error getting body of request, it may not have been passed correctly",
                "Exception": str(e)
            })
        }

    if (not required_args_present):
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps({
                "ERROR":
                "The required arguments [NAME,DESCRIPTION,PICTURE,TEAM,SCHOOL,TECH,COLLEGE,LINKS] are not present"
            })
        }

    # all the args are present so can put in ddb
    input_data = json.loads(event["body"])
    item = {}
    item['name'] = input_data['name']
    item['description'] = input_data['description']
    item['picture'] = input_data['picture']
    item['team'] = input_data['team']
    item['school'] = input_data['school']
    item['tech'] = input_data['tech']
    item['college'] = input_data['college']
    item['links'] = input_data['links']
    item['booth_number'] = input_data['boothNumber']
    item['project_id'] = str(
        uuid.uuid3(NULL_NAMESPACE,
                   str(datetime.now()) + input_data['name']))

    ddb = awsUtils.connect_ddb()
    response = ddb.Table('osu-expo-projects').put_item(Item=item)

    ret = {
        "statusCode": "200",
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Headers": 'Content-Type',
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "POST, OPTIONS",
            "Access-Control-Allow-Credentials": True
        },
        "body": json.dumps(response, default=default)
    }

    return ret
def handler(event, context):

    required_args_present = False
    try:
        required_args_present = set(['project_id']).issubset(
            set(list(json.loads(event["body"]).keys())))
    except Exception as e:
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps({
                "ERROR":
                "Error getting body of request, it may not have been passed correctly",
                "Exception": str(e)
            })
        }

    if (not required_args_present):
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps(
                {"ERROR": "The required argument [project_id] is not present"})
        }

    # all the args are present so can put in ddb
    input_data = json.loads(event["body"])
    name = input_data.get("name", None)
    description = input_data.get("description", None)
    picture = input_data.get("picture", None)
    team = input_data.get("team", None)
    school = input_data.get("school", None)
    tech = input_data.get("tech", None)
    college = input_data.get("college", None)
    links = input_data.get("links", None)
    booth_number = input_data.get("booth_number", None)
    project_id = input_data.get("project_id", None)

    ddb = awsUtils.connect_ddb()
    response = ddb.Table('osu-expo-projects').update_item(
        Key={'project_id': project_id},
        UpdateExpression=
        "SET #NAME_ATTR = :NAME_VAL, #DESC_ATTR = :DESC_VAL, #PICTURE_ATTR = :PICTURE_VAL, #TEAM_ATTR = :TEAM_VAL, #SCHOOL_ATTR = :SCHOOL_VAL, #TECH_ATTR = :TECH_VAL, #COLLEGE_ATTR = :COLLEGE_VAL, #LINKS_ATTR = :LINKS_VAL, #BOOTHNUMBER_ATTR = :BOOTHNUMBER_VAL",
        ExpressionAttributeNames={
            "#NAME_ATTR": "name",
            "#DESC_ATTR": "description",
            "#PICTURE_ATTR": "picture",
            "#TEAM_ATTR": "team",
            "#SCHOOL_ATTR": "school",
            "#TECH_ATTR": "tech",
            "#COLLEGE_ATTR": "college",
            "#LINKS_ATTR": "links",
            "#BOOTHNUMBER_ATTR": "booth_number"
        },
        ExpressionAttributeValues={
            ":NAME_VAL": str(name),
            ":DESC_VAL": str(description),
            ":PICTURE_VAL": str(picture),
            ":TEAM_VAL": team,
            ":SCHOOL_VAL": str(school),
            ":TECH_VAL": str(tech),
            ":COLLEGE_VAL": str(college),
            ":LINKS_VAL": links,
            ":BOOTHNUMBER_VAL": booth_number
        })

    ret = {
        "statusCode": "200",
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Headers": 'Content-Type',
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "POST, OPTIONS",
            "Access-Control-Allow-Credentials": True
        },
        "body": json.dumps(response, default=default)
    }

    return ret
Exemple #5
0
def handler(event, context):

    required_args_present = False
    try:
        required_args_present = set(['user_id']).issubset(
            set(list(json.loads(event["body"]).keys())))
    except Exception as e:
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps({
                "ERROR":
                "Error getting body of request, it may not have been passed correctly",
                "Exception": str(e)
            })
        }

    if (not required_args_present):
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps(
                {"ERROR": "The required argument [EMAIL] is not present"})
        }

    # all the args are present so can put in ddb
    input_data = json.loads(event["body"])
    # using .get and returning None if it doesn't exist since email is the only required arg to create a user
    display_name = input_data.get("display_name", None)
    description = input_data.get("description", None)
    links = input_data.get("links", None)

    # userid based on email and timestamp
    user_id = input_data.get("user_id", None)

    ddb = awsUtils.connect_ddb()
    response = ddb.Table('osu-expo-users').update_item(
        Key={'user_id': user_id},
        UpdateExpression=
        "SET #DISPLAY_NAME_ATTR = :DISPLAY_NAME_VAL, #DESC_ATTR = :DESC_VAL, #LINKS_ATTR = :LINKS_VAL",
        ExpressionAttributeNames={
            "#DISPLAY_NAME_ATTR": "display_name",
            "#DESC_ATTR": "description",
            "#LINKS_ATTR": "links"
        },
        ExpressionAttributeValues={
            ":DISPLAY_NAME_VAL": str(display_name),
            ":DESC_VAL": str(description),
            ":LINKS_VAL": links
        })

    ret = {
        "statusCode": "200",
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Headers": 'Content-Type',
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "POST, OPTIONS",
            "Access-Control-Allow-Credentials": True
        },
        "body": json.dumps(response, default=default)
    }

    return ret
Exemple #6
0
def handler(event, context):

    required_args_present = False
    try:
        required_args_present = set(['email', 'user_id']).issubset(
            set(list(json.loads(event["body"]).keys())))
    except Exception as e:
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps({
                "ERROR":
                "Error getting body of request, it may not have been passed correctly",
                "Exception": str(e)
            })
        }

    if (not required_args_present):
        return {
            "statusCode":
            "400",
            "headers": {
                "Content-Type": "application/json",
                "Access-Control-Allow-Headers": 'Content-Type',
                "Access-Control-Allow-Origin": "*",
                "Access-Control-Allow-Methods": "POST, OPTIONS",
                "Access-Control-Allow-Credentials": True
            },
            "body":
            json.dumps(
                {"ERROR": "The required argument [EMAIL] is not present"})
        }

    # all the args are present so can put in ddb
    input_data = json.loads(event["body"])
    item = {}
    # using .get and returning None if it doesn't exist since email is the only required arg to create a user
    item['email'] = input_data.get("email", None)
    item['display_name'] = input_data.get("display_name", None)
    item['description'] = input_data.get("description", None)
    item['links'] = input_data.get("links", None)

    # userid based on email and timestamp
    item['user_id'] = input_data.get("user_id", None)

    ddb = awsUtils.connect_ddb()
    response = ddb.Table('osu-expo-users').put_item(Item=item)

    ret = {
        "statusCode": "200",
        "headers": {
            "Content-Type": "application/json",
            "Access-Control-Allow-Headers": 'Content-Type',
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "POST, OPTIONS",
            "Access-Control-Allow-Credentials": True
        },
        "body": json.dumps(response, default=default)
    }

    return ret