Skip to content

Commit

Permalink
fix: multiple lambdas related forums (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonNotJson authored Sep 9, 2023
1 parent 6506067 commit d7d1565
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
48 changes: 39 additions & 9 deletions src/lambda/get-all-threads/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,56 @@


@resp_handler
def get_all_threads(uid=""):
def get_all_threads(uid="", board_id=None, last_evaluated_key=None, limit=10):

if board_id:
query_params = {
'KeyConditionExpression': Key('board_id').eq(board_id),
'Limit': limit
}

# If there's a last evaluated key, add it to the query parameters
if last_evaluated_key:
query_params['ExclusiveStartKey'] = {
'board_id': board_id,
'thread_id': last_evaluated_key
}

response = table.query(**query_params)
else:
# If board_id is not provided, scan may be inefficient for large tables
response = table.scan()

response = table.scan()
items = response['Items']

# Add mod field
for item in items:
item['mod'] = False
if 'uid' in item and item['uid'] == uid:
item['mod'] = True

result = {
'items': items,
'last_evaluated_key': response.get('LastEvaluatedKey', {}).get('thread_id')
}

body = JsonPayloadBuilder().add_status(
True).add_data(items).add_message('').compile()
True).add_data(result).add_message('').compile()

return body


def handler(event, context):

uid = ""

if "uid" in event["queryStringParameters"]:
uid = event["queryStringParameters"]["uid"]

return get_all_threads(uid)
board_id = None
last_evaluated_key = None
limit = 10

if "queryStringParameters" in event:
params = event["queryStringParameters"]
uid = params.get("uid", "")
board_id = params.get("board_id", None)
last_evaluated_key = params.get("last_evaluated_key", None)
limit = int(params.get("limit", 10))

return get_all_threads(uid, board_id, last_evaluated_key, limit)
4 changes: 2 additions & 2 deletions src/lambda/patch-comment/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ def patch_comment(thread_id, ts, uid, comment):
"created_at": ts,
},
ConditionExpression=Attr('uid').eq(uid),
UpdateExpression='SET body = :cbody, update_at = :ts',
UpdateExpression='SET body = :cbody, updated_at = :ts',
ExpressionAtrributeValues={
":tbody": [comment['body']],
":cbody": [comment['body']],
":ts": dt_now
}
)
Expand Down
2 changes: 1 addition & 1 deletion src/lambda/patch-thread/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def patch_thread(board_id, uid, thread_id, thread):
"thread_id": thread_id,
},
ConditionExpression=Attr('uid').eq(uid),
UpdateExpression='SET body = :tbody, title = :ttitle, update_at = :ts',
UpdateExpression='SET body = :tbody, title = :ttitle, updated_at = :ts',
ExpressionAttributeValues={
":tbody": thread['body'],
":ttitle": thread['title'],
Expand Down

0 comments on commit d7d1565

Please sign in to comment.