feat: posts have a default author of "anon"
This commit is contained in:
parent
95a16aaa47
commit
2b0ae5925e
@ -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
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user