feat: add author field to post and reply forms
This commit is contained in:
parent
2b0ae5925e
commit
002fc63c90
@ -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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user