fix test code

This commit is contained in:
Kenneth Kehl
2024-10-21 08:01:57 -07:00
parent 3d7ab71555
commit 38a2a87a15
3 changed files with 17 additions and 8 deletions

View File

@@ -16,13 +16,15 @@ def save_complaint(complaint):
def fetch_paginated_complaints(page=1):
# return Complaint.query.order_by(desc(Complaint.created_at)).paginate(
# page=page, per_page=current_app.config["PAGE_SIZE"]
# )
page_size = current_app.config["PAGE_SIZE"]
total_count = db.session.scalar(select(func.count()).select_from(Complaint))
offset = (page - 1) * page_size
stmt = select(Complaint).order_by(desc(Complaint.created_at)).offset(offset).limit(page_size)
stmt = (
select(Complaint)
.order_by(desc(Complaint.created_at))
.offset(offset)
.limit(page_size)
)
result = db.session.execute(stmt).scalars().all()
pagination = Pagination(result, page=page, per_page=page_size, total=total_count)
return pagination