From c7d8960f2cd33142c27715e3ad2931314fb745f2 Mon Sep 17 00:00:00 2001 From: Jish2 Date: Thu, 2 Nov 2023 17:43:35 -0500 Subject: [PATCH] updated pk --- code/student/user.py | 17 +++++++++-------- create_table.py | 31 ------------------------------- 2 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 create_table.py diff --git a/code/student/user.py b/code/student/user.py index 2381947..d4c1f0c 100644 --- a/code/student/user.py +++ b/code/student/user.py @@ -1,7 +1,7 @@ import boto3, os class Student: - uid: int + object_id: str name: str email: str linkedin: str @@ -16,7 +16,7 @@ class Student: work_auth: bool sponsor: bool - def __init__(self, uid, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor): + def __init__(self, object_id, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor): self.uid: uid self.name: name self.email: email @@ -32,20 +32,21 @@ def __init__(self, uid, name, email, linkedin, degree, majors, minors, gpa, year self.work_auth: work_auth self.sponsor: sponsor -client = boto3.client('dynamodb', region_name='us-east-2') +client = boto3.client('dynamodb', region_name=os.environ.get('AWS_REGION', 'us-east-2')) + dynamo_table = "infra-resume-book-users" def get_user(id: int) -> str | None: response = client.get_item( TableName=dynamo_table, Key={ - "uin": id + "object_id": id } ) print(response["Item"]) -def update_user(id: int, body: str) -> str | None: +def update_user(id: str, body: str) -> str | None: temp = {} attributes = {"name", "email", "linkedin", "degree", "majors", "minors", "gpa", "year", "bio", "skills", "position", "work_auth", "sponsor"} for key, value in body.items(): @@ -60,7 +61,7 @@ def update_user(id: int, body: str) -> str | None: response = client.update_item( TableName=dynamo_table, Key={ - 'uin': id + 'object_id': id }, UpdateExpression=update_expression, ExpressionAttributeValues=expression_attribute_values, @@ -99,11 +100,11 @@ def update_user(id: int, body: str) -> str | None: # ':ma': {'BOOL': sponsor}, # } -def register_user(uid, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor): +def register_user(id, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor): client.put_item( TableName=dynamo_table, Item={ - "uid": {'N': uid}, + "object_id": {'N': id}, "name": {'S': name}, "email": {'S': email}, "linkedin": {'S': linkedin}, diff --git a/create_table.py b/create_table.py deleted file mode 100644 index 458fec1..0000000 --- a/create_table.py +++ /dev/null @@ -1,31 +0,0 @@ -import boto3 - -def create_devices_table(dynamodb=None): - dynamodb = boto3.resource( - 'dynamodb', region_name='us-east-2') - table = dynamodb.create_table( - TableName='infra-resume-book-users', - KeySchema=[ - { - 'AttributeName': 'uin', - 'KeyType': 'HASH' # Partition key - } - ], - AttributeDefinitions=[ - { - 'AttributeName': 'uin', - 'AttributeType': 'N' - } - ], - ProvisionedThroughput={ - 'ReadCapacityUnits': 10, - 'WriteCapacityUnits': 10 - } - ) - return table - - -if __name__ == '__main__': - device_table = create_devices_table() - # Print tablle status - print("Status:", device_table.table_status) \ No newline at end of file