paginated all data

This commit is contained in:
Azeez Muibi
2025-04-21 23:40:15 +01:00
parent 678aab5200
commit 90b54d86a4
11 changed files with 582 additions and 348 deletions
+10 -2
View File
@@ -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):
"""
+9 -2
View File
@@ -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