Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
cliarie committed Oct 27, 2023
1 parent 661ed8d commit cb1ebe2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 61 deletions.
4 changes: 2 additions & 2 deletions code/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ def lambda_handler(event, context):
queryParams = {}
print(f"INFO: Processing request: method {method}, path {path}.")
try:
return mapper.execute(method, path, queryParams, event['requestContext']['authorizer'])
return mapper.execute(method, path, queryParams, event['requestContext']['authorizer'], event['body'])
except KeyError:
return mapper.execute(method, path, queryParams, {})
return mapper.execute(method, path, queryParams, {}, "")
34 changes: 9 additions & 25 deletions code/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import json
import traceback

def healthzHandler(context, queryParams):
def healthzHandler(context, queryParams, body):
return {
"statusCode": 200,
"body": "UP"
}
def notImplemented(context, queryParams):
def notImplemented(context, queryParams, body):
return {
"statusCode": 404,
"body": "Method not implemented."
Expand All @@ -24,7 +24,7 @@ def badRequest(message):
"statusCode": 400,
"body": f"Bad request - {message}"
}
def getUploadUrl(context, queryParams):
def getUploadUrl(context, queryParams, body):
rval = {}
try:
url: str = get_upload_url(f"resume_{context['uid']}.pdf")
Expand All @@ -39,7 +39,7 @@ def getUploadUrl(context, queryParams):
traceback.print_exc()
return rval

def getResumeUrl(context, queryParams):
def getResumeUrl(context, queryParams, body):
rval = {}
if not 'uid' in queryParams:
return badRequest("Query parameter 'uid' is missing.")
Expand All @@ -58,10 +58,8 @@ def getResumeUrl(context, queryParams):
traceback.print_exc()
return rval

def getUser(context, queryParams):
def getUser(context, queryParams, body):
rval = {}
if not 'uid' in queryParams:
return badRequest("Query parameter 'uid' is missing.")
try:
user: str = get_user(queryParams['uid'])
rval = {
Expand All @@ -75,28 +73,17 @@ def getUser(context, queryParams):
traceback.print_exc()
return rval

def updateUser(context, queryParams):
def updateUser(context, queryParams, body):
rval = {}
if not 'uid' in queryParams:
return badRequest("Query parameter 'uid' is missing.")
if body == "":
return
try:
update_user(queryParams['uid'])
except:
rval = serverError("Could not get user.")
traceback.print_exc()
return rval

def registerUser(context, queryParams):
rval = {}
if not 'uid' in queryParams:
return badRequest("Query parameter 'uid' is missing.")
try:
register_user(queryParams['uid'])
except:
rval = serverError("Could not get user.")
traceback.print_exc()
return rval

find_handler = {
"GET": {
"/api/v1/healthz": healthzHandler,
Expand All @@ -108,12 +95,9 @@ def registerUser(context, queryParams):
"PUT": {
"/api/v1/student": updateUser
},
"POST": {
"/api/v1/student": registerUser
}
}

def execute(method: str, path: str, queryParams: dict, context: dict) -> dict:
def execute(method: str, path: str, queryParams: dict, context: dict, body: str) -> dict:
try:
func: function = find_handler[method][path]
return func(context, queryParams)
Expand Down
79 changes: 45 additions & 34 deletions code/student/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,50 +35,61 @@ def __init__(self, uid, name, email, linkedin, degree, majors, minors, gpa, year
client = boto3.client('dynamodb', region_name=os.environ.get('AWS_REGION', 'us-east-2'))
dynamo_table = 'infra-resume-book-users'

def get_user(uid: int) -> str | None:
def get_user(id: int) -> str | None:
response = client.get_item(
TableName=dynamo_table,
Key={
'uid': uid
'id': id
}
)

def update_user(uid, name = None, email = None, linkedin = None, degree = None, majors = None, minors = None, gpa = None, year = None, bio = None, skills = None, position = None, work_auth = None, sponsor = None):

def update_user(id, body):
temp = {}
attributes = {"name", "email", "linkedin", "degree", "majors", "minors", "gpa", "year", "bio", "skills", "position", "sponsor"}
for key, value in body.items():
if key in attributes:
temp[key] = value

response = client.update_item(
TableName=dynamo_table,
Key={
'uid': uid
'id': id
},
AttributeUpdates = {
'id': {
'Value' : temp,
},
},
UpdateExpression='SET #n = :n, #e = :e, #l = :l, #d = :d, #ma = list_append(#ma, :ma), #mi = list_append(#mi, :mi), #g = :g, #y = :y, #b = :b, #sk = list_append(#sk, :sk), #p = :p, #sp = :sp',
ExpressionAttributeNames={
'#n': "name",
'#e': "email",
'#l': "linkedin",
'#d': "degree",
'#ma': "majors",
'#mi': "minors",
'#g': "gpa",
'#y': "year",
'#b': "bio",
'#sk': "skills",
'#p': "position",
'#sp': "sponsor"
},
ExpressionAttributeValues={
':n': {'S': name},
':e': {'S': email},
':l': {'S': linkedin},
':d': {'N': degree},
':ma': {'SS': majors},
':mi': {'SS': minors},
':g': {'N': gpa},
':y': {'S': year},
':b': {'S': bio},
':sk': {'SS': skills},
':p': {'N': position},
':w': {'BOOL': work_auth},
':ma': {'BOOL': sponsor},
}
# ExpressionAttributeNames={
# '#n': "name",
# '#e': "email",
# '#l': "linkedin",
# '#d': "degree",
# '#ma': "majors",
# '#mi': "minors",
# '#g': "gpa",
# '#y': "year",
# '#b': "bio",
# '#sk': "skills",
# '#p': "position",
# '#sp': "sponsor"
# },
# ExpressionAttributeValues={
# ':n': {'S': name},
# ':e': {'S': email},
# ':l': {'S': linkedin},
# ':d': {'N': degree},
# ':ma': {'SS': majors},
# ':mi': {'SS': minors},
# ':g': {'N': gpa},
# ':y': {'S': year},
# ':b': {'S': bio},
# ':sk': {'SS': skills},
# ':p': {'N': position},
# ':w': {'BOOL': work_auth},
# ':ma': {'BOOL': sponsor},
# }
)

def register_user(uid, name, email, linkedin, degree, majors, minors, gpa, year, bio, skills, position, work_auth, sponsor):
Expand Down

0 comments on commit cb1ebe2

Please sign in to comment.