init
This commit is contained in:
commit
6dcb020bb5
16 files changed
+488
No files matched your search
@@ -0,0 +1,47 @@
|
||||
import time
|
||||
|
||||
import flask
|
||||
import flask_login
|
||||
|
||||
from . import helpers
|
||||
import database
|
||||
|
||||
|
||||
forum = flask.Blueprint(
|
||||
name='forum_api',
|
||||
import_name=__name__,
|
||||
url_prefix='/forum/'
|
||||
)
|
||||
|
||||
|
||||
@forum.route('/forum/send_message', methods=['POST'])
|
||||
@flask_login.login_required
|
||||
def send_message() -> tuple[str, int]:
|
||||
|
||||
data = flask.request.json
|
||||
|
||||
if not data:
|
||||
return '', 400
|
||||
|
||||
if any([not p in data for p in ['content', 'thread']]):
|
||||
return '', 400
|
||||
|
||||
new_message = database.MessageORM(
|
||||
user=flask_login.current_user.get_id(),
|
||||
content=data['content'],
|
||||
thread=data['thread'],
|
||||
time=int(time.time())
|
||||
)
|
||||
|
||||
if not helpers.user_in_thread(flask_login.current_user.get_id(), data['thread']):
|
||||
return '', 401
|
||||
|
||||
database.insert_message(new_message)
|
||||
|
||||
return '', 201
|
||||
|
||||
@forum.route('/forum/get_threads')
|
||||
@flask_login.login_required
|
||||
def get_forum_threads() -> tuple[str, int]:
|
||||
return '', 200
|
||||
|
||||
Reference in new issue
Block a user