paginated all data
This commit is contained in:
+10
-2
@@ -111,7 +111,8 @@ class Loan(db.Model):
|
||||
|
||||
@classmethod
|
||||
def get_all_loans(cls, customer_id=None, account_id=None, status=None, offer_id=None,
|
||||
product_id=None, start_date=None, end_date=None, due_before=None, due_after=None):
|
||||
product_id=None, start_date=None, end_date=None, due_before=None, due_after=None,
|
||||
page=1, limit=20):
|
||||
"""
|
||||
Get all loans with optional filtering
|
||||
|
||||
@@ -162,7 +163,14 @@ class Loan(db.Model):
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.created_at.desc())
|
||||
|
||||
return query.all()
|
||||
# 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
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
|
||||
@@ -50,7 +50,7 @@ class Transaction(db.Model):
|
||||
return cls.query.get(transaction_id)
|
||||
|
||||
@classmethod
|
||||
def get_all_transactions(cls, account_id=None, transaction_type=None, channel=None, start_date=None, end_date=None):
|
||||
def get_all_transactions(cls, account_id=None, transaction_type=None, channel=None, start_date=None, end_date=None, page=1, limit=20):
|
||||
"""
|
||||
Get all transactions with optional filtering
|
||||
|
||||
@@ -85,4 +85,11 @@ class Transaction(db.Model):
|
||||
# Order by created_at descending (newest first)
|
||||
query = query.order_by(cls.created_at.desc())
|
||||
|
||||
return query.all()
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user