Skip to content

Commit

Permalink
feat: popping data and fixing data type for transact (#388)
Browse files Browse the repository at this point in the history
* feat: fixing post application lambda

* fix: pop user information

* chore: cleaning up unused object

---------

Co-authored-by: Y.H LIEN <[email protected]>
  • Loading branch information
JasonNotJson and LIEN-YUHSIANG authored Nov 16, 2023
1 parent 0558a67 commit 4fe0ac8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/lambda/get-profile/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def get_profile(uid):
"uid").eq(uid), ScanIndexForward=True)["Items"]

item = response[0]

item.pop('uid', None)
item.pop('created_at', None)
item.pop('school_email', None)
item.pop('updated_at', None)

body = JsonPayloadBuilder().add_status(
True).add_data(item).add_message('').compile()
Expand Down
30 changes: 14 additions & 16 deletions src/lambda/post-application/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,6 @@ def post_application(application, uid):

dt_now = datetime.now().strftime('%Y-%m-%dT%H:%M:%S.%f')[:-3] + 'Z'

application_data = {
"type": "application",
"created_at": dt_now,
"uid": uid,
"title": application["title"],
"job_id": application["job_id"],
"company": application["company"],
"email": application["email"],
"name": application["name"],
"agreed": application["agreed"],
}

'''
transact items, ensures that both operations succeed.
If one fails the other automatically fails.
Expand All @@ -41,20 +29,30 @@ def post_application(application, uid):
{
'Put': {
'TableName': table_name,
'Item': application_data
'Item': {
"type": {"S": "application"},
"created_at": {"S": dt_now},
"uid": {"S": uid},
"title": {"S": application["title"]},
"job_id": {"S": application["job_id"]},
"company": {"S": application["company"]},
"email": {"S": application["email"]},
"name": {"S": application["name"]},
"agreed": {"BOOL": application["agreed"]},
}
}
},
{
'Update': {
'TableName': table_name,
'Key': {
"type": "internship",
"created_at": application["created_at"],
"type": {"S": "internship"},
"created_at": {"S": application["created_at"]},
},
'UpdateExpression': 'ADD applicants :uid',
'ConditionExpression': 'attribute_not_exists(applicants) OR NOT contains(applicants, :uid)',
'ExpressionAttributeValues': {
':uid': {uid}
':uid': {"S": uid}
}
}
}
Expand Down

0 comments on commit 4fe0ac8

Please sign in to comment.