added get threads endpoint

This commit is contained in:
0x01FE committed 2025-08-21 16:27:43 -05:00
1 parent af7d682a38
commit c9cf3412d8
5 files changed
+37 -3

No files matched your search

+25 -2
View File
@@ -1,10 +1,12 @@
import time
import dataclasses
import flask
import flask_login
from . import helpers
import database
import mgU
forum = flask.Blueprint(
@@ -42,6 +44,27 @@ def send_message() -> tuple[str, int]:
@forum.route('/forum/get_threads')
@flask_login.login_required
def get_forum_threads() -> tuple[str, int]:
return '', 200
def get_forum_threads() -> tuple[flask.Response, int]:
"""
Get all threads from forums the current user has access to.
"""
user_id: str = flask_login.current_user.get_id()
# Get all forums the user has access to
user_forums: list[mgU.Forum] = database.get_user_forums(int(user_id))
if not user_forums:
return flask.jsonify({"threads": []}), 200
# Get all threads from all user's forums
all_threads: list[mgU.Thread] = []
for forum in user_forums:
if forum.id: # Make sure forum has an ID
forum_threads = database.get_forum_threads(forum.id)
all_threads.extend(forum_threads)
# Convert threads to dictionary format
threads_dict = {"threads": [dataclasses.asdict(thread) for thread in all_threads]}
return flask.jsonify(threads_dict), 200
@@ -0,0 +1,9 @@
{
"threads": [
{
"id": 1,
"name": "Thread Name",
"forum": 1
}
]
}