From 65060673e8246f807fe98dbc846d50ed21828376 Mon Sep 17 00:00:00 2001 From: Jason Park <93040528+JasonNotJson@users.noreply.github.com> Date: Wed, 6 Sep 2023 22:03:19 +0900 Subject: [PATCH] feat: add mod flag (#312) * feat: adding mod flag to get all threads lambda * feat: adding mod flag to board threads --- src/lambda/get-all-threads/index.py | 15 ++++++++++++--- src/lambda/get-board-threads/index.py | 9 ++++++++- src/lambda/syllabus-scraper/const.py | 4 +++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/lambda/get-all-threads/index.py b/src/lambda/get-all-threads/index.py index da1dc7931..e656fc0ac 100644 --- a/src/lambda/get-all-threads/index.py +++ b/src/lambda/get-all-threads/index.py @@ -5,12 +5,16 @@ @resp_handler -def get_all_threads(): - # respons will be table scan by TableName and return first 50 items +def get_all_threads(uid=""): response = table.scan() items = response['Items'] + for item in items: + item['mod'] = False + if 'uid' in item and item['uid'] == uid: + item['mod'] = True + body = JsonPayloadBuilder().add_status( True).add_data(items).add_message('').compile() return body @@ -18,4 +22,9 @@ def get_all_threads(): def handler(event, context): - return get_all_threads() + uid = "" + + if "uid" in event["queryStringParameters"]: + uid = event["queryStringParameters"]["uid"] + + return get_all_threads(uid) diff --git a/src/lambda/get-board-threads/index.py b/src/lambda/get-board-threads/index.py index 2371ccc49..c8fb81075 100644 --- a/src/lambda/get-board-threads/index.py +++ b/src/lambda/get-board-threads/index.py @@ -5,13 +5,18 @@ @resp_handler -def get_board_threads(board_id): +def get_board_threads(board_id, uid=''): results = table.query(KeyConditionExpression=Key( "board_id").eq(board_id), ScanIndexForward=False)["Items"] if not results: raise LookupError + for item in results: + item['mod'] = False + if 'uid' in item and item['uid'] == uid: + item['mod'] = True + body = JsonPayloadBuilder().add_status( True).add_data(results).add_message('').compile() return body @@ -22,5 +27,7 @@ def handler(event, context): params = { "board_id": event["pathParameters"]["board_id"] } + if "uid" in event["queryStringParameters"]: + params["uid"] = event["queryStringParameters"]["uid"] return get_board_threads(**params) diff --git a/src/lambda/syllabus-scraper/const.py b/src/lambda/syllabus-scraper/const.py index 87cf93e4c..92bdca2a8 100644 --- a/src/lambda/syllabus-scraper/const.py +++ b/src/lambda/syllabus-scraper/const.py @@ -79,7 +79,9 @@ "14-809(院生指導室)": "14-809", "14-808(院生指導室)": "14-808", "Seminar room 2 50-303": "50-303", - "drafting room": "57-1F" + "drafting room": "57-1F", + "-": "undecided", + "Faculty Office": "Faculty Office" } user_agents = [