Tests
- Improved directory structure - Added functional and unit tests
This commit is contained in:
40
api/app/blueprints/telegram.py
Normal file
40
api/app/blueprints/telegram.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import os
|
||||
|
||||
from apiflask import APIBlueprint, abort
|
||||
|
||||
from app.db import database as db
|
||||
from app.helper_functions import make_response, get_email_or_abort_401
|
||||
from app.auth import auth
|
||||
from app.schema import TelegramIdSchema, UsersSchema
|
||||
from app.models import User
|
||||
|
||||
telegram_blueprint = APIBlueprint('telegram', __name__, url_prefix='/api')
|
||||
__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
|
||||
|
||||
|
||||
@telegram_blueprint.route('/telegram', methods=['POST'])
|
||||
@telegram_blueprint.output(UsersSchema(many=False), 200)
|
||||
@telegram_blueprint.input(schema=TelegramIdSchema)
|
||||
@telegram_blueprint.auth_required(auth)
|
||||
@telegram_blueprint.doc(summary="Connects telegram user id", description="Connects telegram user id to user account")
|
||||
def add_keyword(data):
|
||||
email = get_email_or_abort_401()
|
||||
|
||||
if not check_if_telegram_user_id_data_exists(data):
|
||||
abort(400, message="User ID missing")
|
||||
|
||||
query_user = db.session.query(User).filter_by(email=email).first()
|
||||
query_user.telegram_user_id = data['telegram_user_id']
|
||||
db.session.commit()
|
||||
|
||||
return make_response(query_user.as_dict(), 200, "Successfully connected telegram user")
|
||||
|
||||
|
||||
def check_if_telegram_user_id_data_exists(data):
|
||||
if "telegram_user_id" not in data:
|
||||
return False
|
||||
|
||||
if data['telegram_user_id'] == "" or data['telegram_user_id'] is None:
|
||||
return False
|
||||
|
||||
return True
|
Reference in New Issue
Block a user