From 2b0ae5925e041da4c98c8cf4ee112929ecab8ef9 Mon Sep 17 00:00:00 2001 From: agatha Date: Sun, 31 Mar 2024 23:45:39 -0400 Subject: [PATCH] feat: posts have a default author of "anon" --- backend/forum.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/backend/forum.py b/backend/forum.py index c3ce424..24887af 100644 --- a/backend/forum.py +++ b/backend/forum.py @@ -7,12 +7,14 @@ app = FastAPI() class Post: id: int thread_id: int + author: str title: str content: str - def __init__(self, id, thread_id, title, content): + def __init__(self, id, thread_id, author, title, content): self.id = id self.thread_id = thread_id + self.author = author self.title = title self.content = content @@ -24,11 +26,13 @@ class PostCreate(BaseModel): class Thread: id: int + author: str title: str closed: bool - def __init__(self, id, title, closed=False): + def __init__(self, id, author, title, closed=False): self.id = id + self.author = author self.title = title self.closed = closed @@ -45,12 +49,14 @@ async def get_threads(): @app.post("/post") async def create_post(data: PostCreate): id = len(POSTS) + 1 + author = 'anon' title = data.title content = data.content # Create thread thread = Thread( id=id, + author=author, title=title ) THREADS.append(thread) @@ -59,6 +65,7 @@ async def create_post(data: PostCreate): post = Post( id=id, thread_id=id, + author=author, title=title, content=content ) @@ -93,6 +100,7 @@ async def reply_to_post(thread_id: int, data: PostCreate): post = Post( id=id, thread_id=parent.id, + author='anon', title=title, content=content )