sub view
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user