add new thread route

This commit is contained in:
2026-04-17 06:33:40 +03:00
parent 7c0cb623e3
commit 54ed6fef3a
3 changed files with 48 additions and 3 deletions

View File

@@ -239,6 +239,21 @@ class Threads(Model):
def stickied(self):
return bool(self.is_stickied)
@classmethod
def new(cls, user_id: int, topic_id: int, title: str, content: str, language: str = 'babycode') -> Threads:
from slugify import slugify
now = int(time.time())
slug = f'{slugify(title)}-{now}'
thread = Threads.create({
'topic_id': topic_id,
'user_id': user_id,
'title': title.strip(),
'slug': slug,
'created_at': int(time.time()),
})
post = Posts.new(user_id, thread.id, content, language)
return thread
class Posts(Model):
FULL_POSTS_QUERY = """
WITH user_badges AS (