backend for bookmark menu

This commit is contained in:
2026-05-30 08:51:53 +03:00
parent 8c87489f70
commit d87d9c2977
6 changed files with 221 additions and 120 deletions

View File

@@ -558,6 +558,21 @@ class BookmarkCollections(Model):
class BookmarkedPosts(Model):
table = 'bookmarked_posts'
@classmethod
def get_for_user(cls, post_id, user_id):
q = """SELECT
bookmarked_posts.id, collection_id, post_id, note
FROM
bookmarked_posts
JOIN
bookmark_collections ON bookmark_collections.id = bookmarked_posts.collection_id
WHERE
post_id = ?
AND
user_id = ?"""
res = db.fetch_one(q, post_id, user_id)
return cls.from_data(res) if res is not None else None
def get_post(self):
return Posts.find({'id': self.post_id})
@@ -565,6 +580,21 @@ class BookmarkedPosts(Model):
class BookmarkedThreads(Model):
table = 'bookmarked_threads'
@classmethod
def get_for_user(cls, thread_id, user_id):
q = """SELECT
bookmarked_threads.id, collection_id, thread_id, note
FROM
bookmarked_threads
JOIN
bookmark_collections ON bookmark_collections.id = bookmarked_threads.collection_id
WHERE
thread_id = ?
AND
user_id = ?"""
res = db.fetch_one(q, thread_id, user_id)
return cls.from_data(res) if res is not None else None
def get_thread(self):
return Threads.find({'id': self.thread_id})