429 lines
13 KiB
Python
429 lines
13 KiB
Python
from flask import Blueprint, request, jsonify, send_from_directory
|
|
from app.api.services import (
|
|
LoginService,
|
|
RegisterService,
|
|
AccountService,
|
|
ProductsService,
|
|
AuthorizationService,
|
|
MyProductsService,
|
|
ContactService,
|
|
OfficeAuthService,
|
|
OfficeDashboardService,
|
|
WebContentsService,
|
|
SubscriptionsService,
|
|
CommonDataService,
|
|
OfficeCustomerService,
|
|
GenerativesService
|
|
)
|
|
from app.utils.logger import logger
|
|
from app.api.middlewares import enforce_json, require_auth
|
|
import os
|
|
from flask_jwt_extended import (
|
|
JWTManager,
|
|
jwt_required,
|
|
create_access_token,
|
|
get_jwt_identity,
|
|
create_refresh_token,
|
|
)
|
|
|
|
import requests
|
|
|
|
api = Blueprint("api", __name__)
|
|
|
|
|
|
# @api.before_request
|
|
# def cors_middleware():
|
|
# """Middleware applied globally to all API routes in this blueprint"""
|
|
# return enforce_json()
|
|
|
|
# Swagger JSON file
|
|
@api.route("/swagger.json", methods=["GET"])
|
|
def swagger_json():
|
|
swagger_dir = os.path.join("swagger")
|
|
return send_from_directory(swagger_dir, "merms_swagger.json")
|
|
|
|
|
|
@api.route("/swagger/<path:filename>")
|
|
def serve_paths(filename):
|
|
swagger_dir = os.path.join("swagger")
|
|
return send_from_directory(swagger_dir, filename)
|
|
|
|
|
|
@api.route("/panel/auth/reset", methods=["POST"])
|
|
# @jwt_required()
|
|
def merms_reset():
|
|
data = request.get_json()
|
|
response = LoginService.process_reset(data)
|
|
return response
|
|
|
|
@api.route("/panel/auth/resetverify", methods=["POST"])
|
|
# @jwt_required()
|
|
def merms_resetverify():
|
|
data = request.get_json()
|
|
response = LoginService.verify_reset(data)
|
|
return response
|
|
|
|
@api.route("/panel/auth/resetcomplete", methods=["POST"])
|
|
# @jwt_required()
|
|
def merms_resetcomplete():
|
|
data = request.get_json()
|
|
response = LoginService.complete_reset(data)
|
|
return response
|
|
|
|
@api.route("/panel/Login", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_login():
|
|
data = request.get_json()
|
|
response = LoginService.process_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/Register", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_register():
|
|
data = request.get_json()
|
|
response = RegisterService.process_request(data)
|
|
return response
|
|
|
|
#/panel/Register/verify
|
|
@api.route("/panel/Register/verify", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_register_verify():
|
|
data = request.get_json()
|
|
response = RegisterService.process_verify(data)
|
|
return response
|
|
|
|
@api.route("/panel/Register/complete", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_register_complete():
|
|
data = request.get_json()
|
|
response = RegisterService.process_complete(data)
|
|
return response
|
|
|
|
@api.route("/panel/account", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_account():
|
|
data = request.get_json()
|
|
response = AccountService.process_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/account-bar", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_account_bar():
|
|
data = request.get_json()
|
|
response = AccountService.process_bar_data(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/bar", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_account_bar2():
|
|
data = request.get_json()
|
|
response = AccountService.process_bar_data(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/actions", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_account_actions():
|
|
data = request.get_json()
|
|
response = AccountService.process_action_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/productsurl", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_account_product_url():
|
|
data = request.get_json()
|
|
response = ProductsService.product_url_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/payments", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_account_payments():
|
|
data = request.get_json()
|
|
response = AccountService.process_payments_data(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/products/url", methods=["POST"])
|
|
def myproduct_url():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Product URL Data ==>>>> {data}")
|
|
response = ProductsService.product_url_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/products/refresh", methods=["POST"])
|
|
def myproduct_refresh():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Product URL Data ==>>>> {data}")
|
|
response = ProductsService.myproduct_refresh_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/products/templates", methods=["POST"])
|
|
# @token_required
|
|
def get_myproduct_templates():
|
|
# Call the Template service
|
|
data = request.get_json()
|
|
# logger.info(f"Route Product Template Data ==>>>> {data}")
|
|
response = MyProductsService.mpproduct_template_data(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/template/activate", methods=["POST"])
|
|
# @token_required
|
|
def get_myproduct_templates_activate():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Product Template Data ==>>>> {data}")
|
|
response = MyProductsService.process_set_template(data)
|
|
return response
|
|
|
|
@api.route("/panel/contacts", methods=["POST"])
|
|
def merms_contacts():
|
|
data = request.get_json()
|
|
# logger.info(f"Route ContactService URL Data ==>>>> {data}")
|
|
response = ContactService.process_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/account/products", methods=["POST"])
|
|
@jwt_required()
|
|
def merms_products():
|
|
data = request.get_json()
|
|
response = ProductsService.process_request(data)
|
|
return response
|
|
|
|
|
|
@api.route("/panel/myproduct/dash", methods=["POST"])
|
|
def myproduct_dash():
|
|
data = request.get_json()
|
|
# logger.info(f"Route MyProduct Data ==>>>> {data}")
|
|
response = MyProductsService.process_request(data)
|
|
return response
|
|
|
|
@api.route("/panel/myproduct/settings", methods=["POST"])
|
|
def myproduct_settings():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Save MyProduct Settings Data ==>>>> {data}")
|
|
response = MyProductsService.process_settings(data)
|
|
return response
|
|
|
|
@api.route("/panel/myproduct/configuration", methods=["POST"])
|
|
def myproduct_configuration():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Save MyProduct Settings Data ==>>>> {data}")
|
|
response = MyProductsService.product_configuration(data)
|
|
return response
|
|
|
|
|
|
@api.route("/panel/myproduct/settings/values", methods=["POST"])
|
|
def myproduct_settings_values():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Get MyProduct Settings Data ==>>>> {data}")
|
|
response = MyProductsService.process_settings_values(data)
|
|
return response
|
|
|
|
@api.route("/panel/subscription/products", methods=["POST"])
|
|
def subscription_products():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Subscription Product Data ==>>>> {data}")
|
|
response = SubscriptionsService.subscription_available_products(data)
|
|
return response
|
|
|
|
#
|
|
@api.route("/panel/subscription/start", methods=["POST"])
|
|
def subscription_sessuib_start():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Subscription Session Start ==>>>> {data}")
|
|
response = SubscriptionsService.subscription_session_start(data)
|
|
return response
|
|
|
|
|
|
# /panel/myproduct/subscription
|
|
@api.route("/panel/myproduct/subscription", methods=["POST"])
|
|
def myproduct_subscription():
|
|
data = request.get_json()
|
|
# logger.info(f"Route MyProduct Data ==>>>> {data}")
|
|
response = MyProductsService.process_subscription(data)
|
|
return response
|
|
|
|
#/panel/myproduct/provision
|
|
@api.route("/panel/myproduct/provision", methods=["POST"])
|
|
def myproduct_provision():
|
|
data = request.get_json()
|
|
# logger.info(f"Route MyProduct Data ==>>>> {data}")
|
|
response = MyProductsService.process_provision(data)
|
|
return response
|
|
|
|
@api.route("/panel/myproduct/provision-actions", methods=["POST"])
|
|
def myproduct_provision_actions():
|
|
data = request.get_json()
|
|
# logger.info(f"Route MyProduct Provision Actions ==>>>> {data}")
|
|
response = MyProductsService.process_provision_actions(data)
|
|
return response
|
|
|
|
@api.route("/stripe/payments", methods=["POST"])
|
|
def stripe_payments_webhook_post():
|
|
try:
|
|
logger.info(f"Route Stripe Webhook POST ENTRY==>>>>")
|
|
data = request.get_json()
|
|
logger.info(f"Route Stripe Webhook POST ==>>>> {data}")
|
|
SubscriptionsService.subscription_webhook_start(data)
|
|
return []
|
|
except Exception as e:
|
|
# A general exception handler for any other type of exception
|
|
logger.error(f"An unexpected error occurred: {e}")
|
|
else:
|
|
# Code to execute if no exception occurs in the try block
|
|
logger.info("Operation successful!")
|
|
finally:
|
|
# Code that will always execute, regardless of whether an exception occurred or not
|
|
logger.info("This block always runs.")
|
|
|
|
|
|
|
|
# /panel/account/calendar
|
|
@api.route("/panel/account/calendar", methods=["POST"])
|
|
def mycalendar_dash():
|
|
data = request.get_json()
|
|
# logger.info(f"Route Calendar Data ==>>>> {data}")
|
|
response = AccountService.process_calendar(data)
|
|
return response
|
|
|
|
# /panel/account/calendar
|
|
@api.route("/panel/account/startprofile", methods=["POST"])
|
|
def account_startprofile():
|
|
data = request.get_json()
|
|
logger.info(f"Route StartProfile Data ==>>>> {data}")
|
|
response = AccountService.process_startprofile(data)
|
|
return response
|
|
|
|
# Health Check Endpoint
|
|
@api.route("/test", methods=["GET"])
|
|
def test_check():
|
|
|
|
data = {"uid": "ok", "token":"jjjfjfjfjfjjf"}
|
|
logger.info(f"Member Actions Error: {data}")
|
|
response = AccountService.process_action_request(data)
|
|
#response = ProductsService.process_request(data)
|
|
return {"status": "ok"}, 200
|
|
|
|
#======================================================
|
|
@api.route('/office/login', methods=['POST'])
|
|
def login():
|
|
data = request.get_json()
|
|
|
|
# Check if username and password are provided
|
|
if not data or 'username' not in data or 'password' not in data:
|
|
return jsonify({
|
|
'error': 'Missing credentials',
|
|
'message': 'Username and password are required'
|
|
}), 400
|
|
|
|
username = data.get('username', '')
|
|
password = data.get('password', '')
|
|
|
|
# Call the login method from AuthService
|
|
result = OfficeAuthService.login(username, password)
|
|
|
|
# Check if result is a tuple (error response)
|
|
if isinstance(result, tuple):
|
|
return jsonify(result[0]), result[1]
|
|
|
|
return jsonify(result)
|
|
|
|
@api.route('/office/dashboard', methods=['GET'])
|
|
# @token_required
|
|
def get_dashboard():
|
|
# Call the dashboard service
|
|
result = OfficeDashboardService.get_dashboard_data()
|
|
return jsonify(result)
|
|
|
|
@api.route('/office/customers', methods=['GET'])
|
|
# @token_required
|
|
def get_customer_office():
|
|
# Call the dashboard service
|
|
filters = {
|
|
'username': request.args.get('username'),
|
|
'email': request.args.get('email'),
|
|
'page': request.args.get('page', 1),
|
|
'limit': request.args.get('limit', 20)
|
|
}
|
|
|
|
response = OfficeCustomerService.get_customer_data(filters)
|
|
return response
|
|
|
|
@api.route('/office/subcriptions', methods=['GET'])
|
|
# @token_required
|
|
def get_subcriptions_list_office():
|
|
# Call the dashboard service
|
|
filters = {
|
|
'product_id': request.args.get('product_id'),
|
|
'member_id': request.args.get('member_id'),
|
|
'page': request.args.get('page', 1),
|
|
'limit': request.args.get('limit', 20)
|
|
}
|
|
|
|
response = SubscriptionsService.get_subscription_data(filters)
|
|
return response
|
|
|
|
@api.route('/office/transaction', methods=['GET'])
|
|
# @token_required
|
|
def get_subscription_office():
|
|
# Call the dashboard service
|
|
result = OfficeDashboardService.get_subscriptions_data()
|
|
return jsonify(result)
|
|
|
|
|
|
#=====================================================
|
|
@api.route('/web/contents', methods=['GET'])
|
|
# @token_required
|
|
def get_web_contents():
|
|
# Call the dashboard service
|
|
provision_uid = request.args.get('provision_uid')
|
|
result = WebContentsService.get_web_contents_data(provision_uid)
|
|
return jsonify(result)
|
|
|
|
#=====================================================
|
|
@api.route('/web/generatives', methods=['GET'])
|
|
def get_refresh_generatives():
|
|
logger.info("START TO ENTER GENERATIVE")
|
|
# Call the dashboard service
|
|
data = []
|
|
result = GenerativesService.process_generatives_list(data)
|
|
return jsonify(result)
|
|
|
|
#===================================================
|
|
# Common Data
|
|
#=====================================================
|
|
@api.route('/panel/common/practice', methods=['POST'])
|
|
# @token_required
|
|
def common_practice():
|
|
# Call the dashboard service
|
|
data = request.get_json()
|
|
logger.info(f"Route common Practice Data ==>>>> {data}")
|
|
response = CommonDataService.available_practices(data)
|
|
return response
|
|
# return jsonify(result)
|
|
#===================================================
|
|
|
|
|
|
|
|
# Health Check Endpoint
|
|
@api.route("/health", methods=["GET"])
|
|
def health_check():
|
|
return {"status": "ok"}, 200
|
|
|
|
|
|
|
|
# Authorize endpoint
|
|
@api.route("/Authorize", methods=["POST"])
|
|
def authorize():
|
|
data = request.get_json()
|
|
# logger.info(f"Authorize request received: {data}")
|
|
response = AuthorizationService.process_request(data)
|
|
return response
|
|
|
|
|
|
# Authorize refresh endpoint
|
|
@api.route("/AuthorizeRefresh", methods=["POST"])
|
|
@jwt_required(refresh=True)
|
|
def refresh():
|
|
data = request.get_json()
|
|
# logger.info(f"Authorize refresh request received: {data}")
|
|
response = AuthorizationService.process_refresh_request()
|
|
return response
|