sub office
This commit is contained in:
@@ -291,7 +291,20 @@ def get_customer_office():
|
||||
|
||||
response = OfficeCustomerService.get_customer_data(filters)
|
||||
return response
|
||||
# return jsonify(result)
|
||||
|
||||
@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 = SubscriptionService.get_subscription_data(filters)
|
||||
return response
|
||||
|
||||
@api.route('/office/transaction', methods=['GET'])
|
||||
# @token_required
|
||||
|
||||
@@ -4,10 +4,70 @@ from app.api.services.base_service import BaseService
|
||||
from sqlalchemy import func, desc
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from app.api.schemas.user import UserSchema
|
||||
from app.models import Members
|
||||
from app.models import Members, MembersProducts
|
||||
from app.extensions import db
|
||||
|
||||
class SubscriptionService(BaseService):
|
||||
# def get_all_subscriptions(cls, product_id=None, member_id=None, page=1, limit=20):
|
||||
@staticmethod
|
||||
def get_subscription_data(filters=None):
|
||||
try:
|
||||
if filters is None:
|
||||
filters = {}
|
||||
|
||||
# Extract filters
|
||||
product_id = filters.get('product_id')
|
||||
member_id = filters.get('member_id')
|
||||
|
||||
# Extract pagination parameters
|
||||
page = int(filters.get('page', 1))
|
||||
limit = int(filters.get('limit', 20))
|
||||
|
||||
# Ensure page and limit are valid
|
||||
if page < 1:
|
||||
page = 1
|
||||
if limit < 1 or limit > 100:
|
||||
limit = 20
|
||||
|
||||
membersSubList, total_count = MembersProducts.get_all_subscriptions(product_id,member_id,page,limit)
|
||||
# Convert loans to dictionary format
|
||||
member_sub_data = []
|
||||
for subs in membersSubList:
|
||||
member_sub_data.append({
|
||||
'id': subs.id,
|
||||
'member_id': subs.member_id,
|
||||
'product_id': subs.product_id,
|
||||
'internal_url': subs.internal_url,
|
||||
'external_url': subs.external_url,
|
||||
'dns_group': subs.dns_group,
|
||||
'status': subs.status,
|
||||
'updated': subs.updated,
|
||||
"added": subs.added,
|
||||
})
|
||||
|
||||
# Calculate total pages
|
||||
total_pages = (total_count + limit - 1) // limit
|
||||
|
||||
response_data = {
|
||||
'subscriptions': member_sub_data,
|
||||
'count': len(member_sub_data),
|
||||
'pagination': {
|
||||
'total_count': total_count,
|
||||
'total_pages': total_pages,
|
||||
'current_page': page,
|
||||
'limit': limit,
|
||||
'has_next': page < total_pages,
|
||||
'has_prev': page > 1
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@staticmethod
|
||||
def subscription_available_products(data):
|
||||
|
||||
+2
-35
@@ -123,45 +123,12 @@ class Members(db.Model):
|
||||
|
||||
query = cls.query
|
||||
logger.info(f"Get all customer back")
|
||||
# Apply filters if provided
|
||||
# if id:
|
||||
# query = query.filter(cls.id == id)
|
||||
|
||||
if username:
|
||||
query = query.filter(cls.customer_id == username)
|
||||
query = query.filter(cls.username == username)
|
||||
|
||||
if email:
|
||||
query = query.filter(cls.account_id == email)
|
||||
|
||||
# if status:
|
||||
# query = query.filter(cls.status == status)
|
||||
#
|
||||
# if tenor:
|
||||
# query = query.filter(cls.tenor == tenor)
|
||||
#
|
||||
# if offer_id:
|
||||
# query = query.filter(cls.offer_id == offer_id)
|
||||
#
|
||||
# if product_id:
|
||||
# query = query.filter(cls.product_id == product_id)
|
||||
#
|
||||
# if transaction_id:
|
||||
# query = query.filter(cls.transaction_id == transaction_id)
|
||||
#
|
||||
# if original_transaction:
|
||||
# query = query.filter(cls.original_transaction == original_transaction)
|
||||
#
|
||||
# if start_date:
|
||||
# query = query.filter(cls.created_at >= start_date)
|
||||
#
|
||||
# if end_date:
|
||||
# query = query.filter(cls.created_at <= end_date)
|
||||
#
|
||||
# if due_before:
|
||||
# query = query.filter(cls.due_date <= due_before)
|
||||
#
|
||||
# if due_after:
|
||||
# query = query.filter(cls.due_date >= due_after)
|
||||
query = query.filter(cls.email == email)
|
||||
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.added.desc())
|
||||
|
||||
@@ -103,6 +103,30 @@ class MembersProducts(db.Model):
|
||||
return subscription
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_all_subscriptions(cls, product_id=None, member_id=None, page=1, limit=20):
|
||||
|
||||
query = cls.query
|
||||
logger.info(f"Get all customer back")
|
||||
|
||||
if member_id:
|
||||
query = query.filter(cls.member_id == member_id)
|
||||
|
||||
if product_id:
|
||||
query = query.filter(cls.product_id == product_id)
|
||||
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.added.desc())
|
||||
|
||||
# Get total count before pagination
|
||||
total_count = query.count()
|
||||
|
||||
# Apply pagination
|
||||
offset = (page - 1) * limit
|
||||
query = query.limit(limit).offset(offset)
|
||||
|
||||
return query.all(), total_count
|
||||
|
||||
# @classmethod
|
||||
# def save_update_product_settings(cls, member_id,subscription_uid,product_id,settings_key,setting_type,setting_value ):
|
||||
# logger.info(f"settings_key : {settings_key}")
|
||||
|
||||
Reference in New Issue
Block a user