From 4228107b54ca7c1c632e8fdb44de1c831415d30b Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 31 Mar 2024 23:57:09 -0400 Subject: [PATCH] refactor: move unknown parent thread check --- backend/forum.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/forum.py b/backend/forum.py index ae272af..92dd41c 100644 --- a/backend/forum.py +++ b/backend/forum.py @@ -95,22 +95,22 @@ async def reply_to_post(thread_id: int, data: PostCreate): if thread.id == thread_id: parent = thread - if parent: - id = len(POSTS) + 1 - author = data.author - title = data.title - content = data.content + if parent is None: + return {'error': 'could not find parent thread'} - # Create post - post = Post( - id=id, - thread_id=parent.id, - author=author, - title=title, - content=content - ) - POSTS.append(post) + id = len(POSTS) + 1 + author = data.author + title = data.title + content = data.content - return post + # Create post + post = Post( + id=id, + thread_id=parent.id, + author=author, + title=title, + content=content + ) + POSTS.append(post) - return {'error': 'could not find parent thread'} + return post