Skip to content

Commit

Permalink
feat: refactoring sorting method
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonNotJson committed Sep 10, 2023
1 parent 71d1904 commit e457c32
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lambda/get-all-threads/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def get_all_threads(uid, index, num, school, tags, board_id):

print(f"Items after filtering: {items}")

if not board_id:
items = sorted(items, key=lambda x: x.get(
'created_at', ''), reverse=True)

start_index = index
end_index = min(len(items), start_index+num)
paginated_items = items[start_index:end_index]
Expand All @@ -42,9 +46,9 @@ def get_all_threads(uid, index, num, school, tags, board_id):
item['mod'] = True
item.pop('uid', None)

if not board_id:
paginated_items = sorted(paginated_items, key=lambda x: x.get(
'thread_id', ''), reverse=True)
# if not board_id:
# paginated_items = sorted(paginated_items, key=lambda x: x.get(
# 'thread_id', ''), reverse=True)

body = JsonPayloadBuilder().add_status(
True).add_data(paginated_items).add_message(end_index).compile()
Expand Down

0 comments on commit e457c32

Please sign in to comment.