From 002fc63c90bb6f65b91344d886d47a1708625852 Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 31 Mar 2024 23:55:00 -0400 Subject: [PATCH] feat: add author field to post and reply forms --- backend/forum.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/forum.py b/backend/forum.py index 24887af..ae272af 100644 --- a/backend/forum.py +++ b/backend/forum.py @@ -5,6 +5,7 @@ app = FastAPI() class Post: + """Post is a single forum post or reply""" id: int thread_id: int author: str @@ -20,11 +21,14 @@ class Post: class PostCreate(BaseModel): + """Used when creating posts and replies""" + author: str = 'anon' title: str content: str class Thread: + """Thread is a collection of a post and its replies""" id: int author: str title: str @@ -49,7 +53,7 @@ async def get_threads(): @app.post("/post") async def create_post(data: PostCreate): id = len(POSTS) + 1 - author = 'anon' + author = data.author title = data.title content = data.content @@ -93,6 +97,7 @@ async def reply_to_post(thread_id: int, data: PostCreate): if parent: id = len(POSTS) + 1 + author = data.author title = data.title content = data.content @@ -100,7 +105,7 @@ async def reply_to_post(thread_id: int, data: PostCreate): post = Post( id=id, thread_id=parent.id, - author='anon', + author=author, title=title, content=content )