From 862eaeb0754d4e10b2bbc124a8c33dd9597ef70c Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Mon, 29 Sep 2025 11:52:58 -0400 Subject: [PATCH] sub view --- app/api/routes/routes.py | 11 +++++ app/api/services/office_dashboard.py | 65 ++++++++++++++++++++++++++++ app/models/products_templates.py | 3 +- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/app/api/routes/routes.py b/app/api/routes/routes.py index 1b73e8e..6bc84d5 100644 --- a/app/api/routes/routes.py +++ b/app/api/routes/routes.py @@ -404,6 +404,17 @@ def get_subcriptions_list_office(): response = SubscriptionsService.get_subscription_data(filters) return response +@api.route('/office/subcription-view', methods=['GET']) +# @token_required +def get_subcriptions_view_office(): + # Call the dashboard service + filters = { + 'subscription_uid': request.args.get('subscription_uid') + } + + response = OfficeDashboardService.get_subscription_view_data(filters) + return response + @api.route('/office/billings', methods=['GET']) # @token_required diff --git a/app/api/services/office_dashboard.py b/app/api/services/office_dashboard.py index 77cc41b..ea400be 100644 --- a/app/api/services/office_dashboard.py +++ b/app/api/services/office_dashboard.py @@ -273,3 +273,68 @@ class OfficeDashboardService(BaseService): except Exception as e: logger.error(f"An error occurred while getting cusomer data: {str(e)}", exc_info=True) return jsonify({"message": "Internal Server Error"}), 500 + + @staticmethod + def get_subscription_view_data(filters=None): + try: + if filters is None: + filters = {} + # Extract filters + subscription_uid = filters.get('subscription_uid') + + member_sub = [] + product_templates_data = [] + templates_data = [] + + membersSubResult, total_count = MembersProducts.get_member_product_by_subscription_uid(subscription_uid) + if membersSubResult: + member_sub = { + 'id': membersSubResult.id, + 'subscription_uid': str(membersSubResult.uid), + 'member_id': membersSubResult.member_id, + 'product_id': membersSubResult.product_id, + 'internal_url': membersSubResult.internal_url, + 'external_url': membersSubResult.external_url, + 'dns_group': membersSubResult.dns_group, + 'product_template': membersSubResult.product_template, + 'custom_template': membersSubResult.custom_template, + 'status': membersSubResult.status, + 'updated': membersSubResult.updated, + "added": membersSubResult.added, + } + + templates = CustomTemplates.get_custom_template_for_office(filters) + + if templates: + for t in templates: + templates_data.append({ + 'id': t.id, + 'uid': t.uid, + 'custom_id': t.custom_id, + 'provision_name': t.provision_name, + 'added': t.added.isoformat() if t.added else None, + }) + + product_templates = ProductsTemplates.get_template_by_product_id(membersSubResult.product_id) + + if product_templates: + for t in product_templates: + product_templates_data.append({ + 'id': t.id, + 'uid': t.uid, + 'product_id': t.product_id, + 'provision_name': t.provision_name, + 'added': t.added.isoformat() if t.added else None, + }) + + response_data = { + 'subscription': member_sub, + 'available_templates': product_templates_data, + 'available_custom_templates': templates_data + } + + return response_data + + except Exception as e: + logger.error(f"An error occurred while getting dashboard data: {str(e)}", exc_info=True) + return jsonify({"message": "Internal Server Error"}), 500 diff --git a/app/models/products_templates.py b/app/models/products_templates.py index 20e9d61..bd9db4f 100644 --- a/app/models/products_templates.py +++ b/app/models/products_templates.py @@ -22,7 +22,8 @@ class ProductsTemplates(db.Model): templates = cls.query.filter_by(product_id=str(product_id)).all() if not templates: - raise ValueError(f"Templates with Product ID {product_id} not found") + # raise ValueError(f"Templates with Product ID {product_id} not found") + return None return templates @classmethod