From 92c8c02d296ffa669292930dc851d02eb3bdcf9c Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Mon, 7 Jul 2025 19:17:14 -0400 Subject: [PATCH] my path --- app/api/routes/routes.py | 8 ++++ app/api/services/myproduct.py | 76 +++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 68c78dc..76366de 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -150,6 +150,14 @@ def myproduct_subscription(): 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 + # /panel/account/calendar @api.route("/panel/account/calendar", methods=["POST"]) diff --git a/app/api/services/myproduct.py b/app/api/services/myproduct.py index a2ea27c..0f7e15f 100644 --- a/app/api/services/myproduct.py +++ b/app/api/services/myproduct.py @@ -16,6 +16,82 @@ from app.config import Config class MyProductsService(BaseService): + @staticmethod + def process_provision(data): + try: + with db.session.begin(): + logger.info(f"Incoming MyProduct data ==>>>> {data}") + validated_data = MyProductsService.validate_data(data, MyProductSchema()) + token = validated_data.get('token') + uid = validated_data.get('uid') + member_data = Members.get_member_by_uid(uid) + member_id = member_data.id + + product_id = validated_data.get('product_id') + product_data = Products.get_product_by_product_id(product_id) + + if not product_data: + return { + "message": "Please provide product_id", + "data": None, + "error": "Bad request" + }, 400 + + logger.info(f"GET HERE ******************************** : {data}", exc_info=True) + subscription = MembersProducts.get_member_product_by_product_member_id(member_id, product_id) + + # if not subscription: + # logger.error(f"Ready to add data to tables") + # response_data = { + # "subscription": mumberSub, + # "member_id": member_id, + # "error": "already_subscribed", + # "uid": uid + # } + # return ResponseHelper.success(data=response_data) + + # internal_url = str(random.randint(10000, 99999)) + ".devprov.mermsemr.com" + #INSERT_NEW_PRODUCT = "INSERT INTO members_products (member_id ,product_id,status,internal_url) VALUES (%s, %s, %s, %s)" + # val_insert = (member_id, product_id,6,internal_url) + # status = 6 + # subscription = MembersProducts.create_subscription(member_id ,product_id,status,internal_url) + + # response_data = { + # "subscription_uid": subscription.uid, + # "subscription_id": subscription.id, + # "internal_url": subscription.internal_url, + # "member_id": member_id, + # "uid": uid + # } + provision_activities=[] + response_data = { + "subscription_uid": subscription.uid, + "subscription_id": subscription.id, + "last_update": datetime.datetime.utcnow(), + "percent_completed": random.randint(10, 99), + "activities": provision_activities + } + return ResponseHelper.success(data=response_data) + + + except ValidationError as err: + + logger.error(f"Validation Error: {getattr(err, 'messages', str(err))}") + db.session.rollback() + return ResponseHelper.unprocessable_entity(result_description="Validation exception") + + except ValueError as err: + logger.error(f"{getattr(err, 'messages', str(err))}") + db.session.rollback() + return ResponseHelper.error(result_description=str(err)) + + except Exception as e: + logger.error(f"An error occurred: {str(e)}", exc_info=True) + db.session.rollback() + return ResponseHelper.internal_server_error() + + + @staticmethod def process_subscription(data): try: