Paginate the function to get all complaints

The DAO function to get all complaints has been paginated and the
endpoint which uses it has been updated to take a page number as a query
parameter.
This commit is contained in:
Katie Smith
2018-07-02 17:19:23 +01:00
parent e3b3a407c9
commit 3398e4cf93
4 changed files with 75 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
from datetime import timedelta
from flask import current_app
from sqlalchemy import desc
from app import db
@@ -13,6 +14,15 @@ def save_complaint(complaint):
db.session.add(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']
)
def fetch_complaints_by_service(service_id):
return Complaint.query.filter_by(service_id=service_id).order_by(desc(Complaint.created_at)).all()