-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding functionalities for user thread (#324)
* feat: adding functionalities for user thread * chore: typo fix * feat: changing schema model to an empty model
- Loading branch information
1 parent
a97abc1
commit 171dfec
Showing
7 changed files
with
79 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from boto3.dynamodb.conditions import Key, Attr | ||
import boto3 | ||
from datetime import datetime | ||
from utils import JsonPayloadBuilder, table, resp_handler | ||
|
||
|
||
@resp_handler | ||
def get_user_threads(uid): | ||
|
||
# Query the GSI | ||
response = table.query( | ||
IndexName='UidbyThreadIDIndex', # Replace with your actual GSI name | ||
KeyConditionExpression=Key('uid').eq(uid), | ||
FilterExpression=Attr('new_comment').eq(True), | ||
ScanIndexForward=False # Sorting by thread_id in descending order | ||
) | ||
|
||
results = response['Items'] | ||
|
||
# Count the threads with new comments | ||
new_comment_count = len(results) | ||
|
||
# Collect the thread_ids | ||
thread_ids = [item['thread_id'] for item in results] | ||
|
||
# Determine the response data based on new_comment_count | ||
response_data = True if new_comment_count > 1 else { | ||
'thread_ids': thread_ids, 'new_comment_count': new_comment_count} | ||
|
||
body = JsonPayloadBuilder().add_status(True)\ | ||
.add_data(response_data)\ | ||
.add_message('Fetched successfully').compile() | ||
|
||
return body | ||
|
||
|
||
def handler(event, context): | ||
uid = event['queryStringParameters'].get('uid', '') | ||
# index = event['queryStringParameters'].get('index', '0') | ||
# num = event['queryStringParameters'].get('num', '10') | ||
|
||
return get_user_threads(uid) |
File renamed without changes.