Added endpoint to set telegram user id
This commit is contained in:
parent
12d59d69ff
commit
62d66c1d6f
42
api/api_blueprint_telegram.py
Normal file
42
api/api_blueprint_telegram.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
from apiflask import APIBlueprint, abort
|
||||||
|
|
||||||
|
from db import db
|
||||||
|
from helper_functions import make_response, get_email_or_abort_401
|
||||||
|
from auth import auth
|
||||||
|
from schema import TelegramIdSchema, UsersSchema
|
||||||
|
from 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()
|
||||||
|
|
||||||
|
check_if_telegram_user_id_data_exists(data)
|
||||||
|
|
||||||
|
query_user = db.session.query(User).filter_by(email=email).first()
|
||||||
|
|
||||||
|
if query_user is None: # Username doesn't exist
|
||||||
|
abort(500, message="Unable to login")
|
||||||
|
|
||||||
|
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:
|
||||||
|
abort(400, message="User ID missing")
|
||||||
|
|
||||||
|
if data['telegram_user_id'] == "" or data['telegram_user_id'] is None:
|
||||||
|
abort(400, message="User ID missing")
|
@ -5,6 +5,11 @@ from apiflask import APIFlask
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
|
from api.api_blueprint_keyword import keyword_blueprint
|
||||||
|
from api.api_blueprint_portfolio import portfolio_blueprint
|
||||||
|
from api.api_blueprint_shares import shares_blueprint
|
||||||
|
from api.api_blueprint_transactions import transaction_blueprint
|
||||||
|
from api.api_blueprint_telegram import telegram_blueprint
|
||||||
from api.helper_functions import hash_password
|
from api.helper_functions import hash_password
|
||||||
from models import *
|
from models import *
|
||||||
from api_blueprint_user import users_blueprint
|
from api_blueprint_user import users_blueprint
|
||||||
@ -29,6 +34,7 @@ def create_app():
|
|||||||
application.register_blueprint(transaction_blueprint)
|
application.register_blueprint(transaction_blueprint)
|
||||||
application.register_blueprint(portfolio_blueprint)
|
application.register_blueprint(portfolio_blueprint)
|
||||||
application.register_blueprint(users_blueprint)
|
application.register_blueprint(users_blueprint)
|
||||||
|
application.register_blueprint(telegram_blueprint)
|
||||||
|
|
||||||
@application.before_first_request
|
@application.before_first_request
|
||||||
def init_database():
|
def init_database():
|
||||||
|
Loading…
Reference in New Issue
Block a user