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:
|
class Post:
|
||||||
|
"""Post is a single forum post or reply"""
|
||||||
id: int
|
id: int
|
||||||
thread_id: int
|
thread_id: int
|
||||||
author: str
|
author: str
|
||||||
@ -20,11 +21,14 @@ class Post:
|
|||||||
|
|
||||||
|
|
||||||
class PostCreate(BaseModel):
|
class PostCreate(BaseModel):
|
||||||
|
"""Used when creating posts and replies"""
|
||||||
|
author: str = 'anon'
|
||||||
title: str
|
title: str
|
||||||
content: str
|
content: str
|
||||||
|
|
||||||
|
|
||||||
class Thread:
|
class Thread:
|
||||||
|
"""Thread is a collection of a post and its replies"""
|
||||||
id: int
|
id: int
|
||||||
author: str
|
author: str
|
||||||
title: str
|
title: str
|
||||||
@ -49,7 +53,7 @@ async def get_threads():
|
|||||||
@app.post("/post")
|
@app.post("/post")
|
||||||
async def create_post(data: PostCreate):
|
async def create_post(data: PostCreate):
|
||||||
id = len(POSTS) + 1
|
id = len(POSTS) + 1
|
||||||
author = 'anon'
|
author = data.author
|
||||||
title = data.title
|
title = data.title
|
||||||
content = data.content
|
content = data.content
|
||||||
|
|
||||||
@ -93,6 +97,7 @@ async def reply_to_post(thread_id: int, data: PostCreate):
|
|||||||
|
|
||||||
if parent:
|
if parent:
|
||||||
id = len(POSTS) + 1
|
id = len(POSTS) + 1
|
||||||
|
author = data.author
|
||||||
title = data.title
|
title = data.title
|
||||||
content = data.content
|
content = data.content
|
||||||
|
|
||||||
@ -100,7 +105,7 @@ async def reply_to_post(thread_id: int, data: PostCreate):
|
|||||||
post = Post(
|
post = Post(
|
||||||
id=id,
|
id=id,
|
||||||
thread_id=parent.id,
|
thread_id=parent.id,
|
||||||
author='anon',
|
author=author,
|
||||||
title=title,
|
title=title,
|
||||||
content=content
|
content=content
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user