mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-05 02:41:14 -05:00
fix pagination maybe
This commit is contained in:
@@ -6,8 +6,7 @@ from flask import current_app
|
|||||||
from sqlalchemy import and_, asc, desc, func, select
|
from sqlalchemy import and_, asc, desc, func, select
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
|
from app.dao.pagination import Pagination
|
||||||
# from app.dao.pagination import Pagination
|
|
||||||
from app.enums import JobStatus
|
from app.enums import JobStatus
|
||||||
from app.models import (
|
from app.models import (
|
||||||
FactNotificationStatus,
|
FactNotificationStatus,
|
||||||
@@ -67,25 +66,26 @@ def dao_get_jobs_by_service_id(
|
|||||||
if statuses is not None and statuses != [""]:
|
if statuses is not None and statuses != [""]:
|
||||||
query_filter.append(Job.job_status.in_(statuses))
|
query_filter.append(Job.job_status.in_(statuses))
|
||||||
|
|
||||||
# total_items = db.session.execute(
|
total_items = db.session.execute(
|
||||||
# select(func.count()).select_from(Job).filter(*query_filter)
|
select(func.count()).select_from(Job).filter(*query_filter)
|
||||||
# ).scalar_one()
|
).scalar_one()
|
||||||
|
|
||||||
# stmt = (
|
offset = (page - 1) * page_size
|
||||||
# select(Job)
|
stmt = (
|
||||||
# .filter(*query_filter)
|
select(Job)
|
||||||
# .order_by(Job.processing_started.desc(), Job.created_at.desc())
|
.filter(*query_filter)
|
||||||
# .limit(page_size)
|
|
||||||
# .offset(page)
|
|
||||||
# )
|
|
||||||
# items = db.session.execute(stmt).scalars().all()
|
|
||||||
# return Pagination(items, page, page_size, total_items)
|
|
||||||
|
|
||||||
return (
|
|
||||||
Job.query.filter(*query_filter)
|
|
||||||
.order_by(Job.processing_started.desc(), Job.created_at.desc())
|
.order_by(Job.processing_started.desc(), Job.created_at.desc())
|
||||||
.paginate(page=page, per_page=page_size)
|
.limit(page_size)
|
||||||
|
.offset(offset)
|
||||||
)
|
)
|
||||||
|
items = db.session.execute(stmt).scalars().all()
|
||||||
|
return Pagination(items, page, page_size, total_items)
|
||||||
|
|
||||||
|
# return (
|
||||||
|
# Job.query.filter(*query_filter)
|
||||||
|
# .order_by(Job.processing_started.desc(), Job.created_at.desc())
|
||||||
|
# .paginate(page=page, per_page=page_size)
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
def dao_get_scheduled_job_stats(
|
def dao_get_scheduled_job_stats(
|
||||||
|
|||||||
Reference in New Issue
Block a user