add bookmark schema
This commit is contained in:
@@ -101,6 +101,11 @@ class Users(Model):
|
||||
|
||||
return False
|
||||
|
||||
def get_bookmark_collections(self):
|
||||
q = 'SELECT id FROM bookmark_collections WHERE user_id = ? ORDER BY sort_order ASC'
|
||||
res = db.query(q, self.id)
|
||||
return [BookmarkCollections.find({'id': bc['id']}) for bc in res]
|
||||
|
||||
|
||||
class Topics(Model):
|
||||
table = "topics"
|
||||
@@ -225,7 +230,7 @@ class Threads(Model):
|
||||
class Posts(Model):
|
||||
FULL_POSTS_QUERY = """
|
||||
SELECT
|
||||
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered, threads.slug AS thread_slug, threads.is_locked AS thread_is_locked
|
||||
posts.id, posts.created_at, post_history.content, post_history.edited_at, users.username, users.status, avatars.file_path AS avatar_path, posts.thread_id, users.id AS user_id, post_history.original_markup, users.signature_rendered, threads.slug AS thread_slug, threads.is_locked AS thread_is_locked, threads.title AS thread_title
|
||||
FROM
|
||||
posts
|
||||
JOIN
|
||||
@@ -239,6 +244,10 @@ class Posts(Model):
|
||||
|
||||
table = "posts"
|
||||
|
||||
def get_full_post_view(self):
|
||||
q = f'{self.FULL_POSTS_QUERY} WHERE posts.id = ?'
|
||||
return db.fetch_one(q, self.id)
|
||||
|
||||
class PostHistory(Model):
|
||||
table = "post_history"
|
||||
|
||||
@@ -317,3 +326,45 @@ class PasswordResetLinks(Model):
|
||||
|
||||
class InviteKeys(Model):
|
||||
table = 'invite_keys'
|
||||
|
||||
|
||||
class BookmarkCollections(Model):
|
||||
table = 'bookmark_collections'
|
||||
|
||||
@classmethod
|
||||
def create_default(cls, user_id):
|
||||
q = """INSERT INTO bookmark_collections (user_id, name, is_default, sort_order)
|
||||
VALUES (?, "Bookmarks", 1, 0) RETURNING id
|
||||
"""
|
||||
res = db.fetch_one(q, user_id)
|
||||
|
||||
def has_posts(self):
|
||||
q = 'SELECT EXISTS(SELECT 1 FROM bookmarked_posts WHERE collection_id = ?) as e'
|
||||
res = db.fetch_one(q, self.id)['e']
|
||||
return int(res) == 1
|
||||
|
||||
def has_threads(self):
|
||||
q = 'SELECT EXISTS(SELECT 1 FROM bookmarked_threads WHERE collection_id = ?) as e'
|
||||
res = db.fetch_one(q, self.id)['e']
|
||||
return int(res) == 1
|
||||
|
||||
def is_empty(self):
|
||||
return not (self.has_posts() or self.has_threads())
|
||||
|
||||
def get_threads(self):
|
||||
q = 'SELECT thread_id FROM bookmarked_threads WHERE collection_id = ?'
|
||||
res = db.query(q, self.id)
|
||||
return [Threads.find({'id': bt['thread_id']}) for bt in res]
|
||||
|
||||
def get_posts(self):
|
||||
q = 'SELECT post_id FROM bookmarked_posts WHERE collection_id = ?'
|
||||
res = db.query(q, self.id)
|
||||
return [Posts.find({'id': bt['post_id']}) for bt in res]
|
||||
|
||||
|
||||
class BookmarkedPosts(Model):
|
||||
table = 'bookmarked_posts'
|
||||
|
||||
|
||||
class BookmarkedThreads(Model):
|
||||
table = 'bookmarked_threads'
|
||||
|
||||
Reference in New Issue
Block a user