add new thread route
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user