From c2acfda9fb23bdb4ed39d9ef0617ab29e1fbd29f Mon Sep 17 00:00:00 2001 From: Taha Yassine Kraiem Date: Tue, 15 Nov 2022 18:22:07 +0100 Subject: [PATCH] feat(chalice): changed get record feat(chalice): paginate through records --- ee/api/chalicelib/core/assist_records.py | 6 ++++-- ee/api/routers/ee.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ee/api/chalicelib/core/assist_records.py b/ee/api/chalicelib/core/assist_records.py index 18c166445..af402c617 100644 --- a/ee/api/chalicelib/core/assist_records.py +++ b/ee/api/chalicelib/core/assist_records.py @@ -29,7 +29,7 @@ def search_records(project_id, data: schemas_ee.AssistRecordSearchPayloadSchema, "assist_records.created_at<=%(endDate)s"] params = {"tenant_id": context.tenant_id, "project_id": project_id, "startDate": data.startDate, "endDate": data.endDate, - "p_start": (data.page - 1) * data.limit, "p_end": data.page * data.limit, + "p_start": (data.page - 1) * data.limit, "p_limit": data.limit, **data.dict()} if data.user_id is not None: conditions.append("assist_records.user_id=%(user_id)s") @@ -43,7 +43,9 @@ def search_records(project_id, data: schemas_ee.AssistRecordSearchPayloadSchema, FROM assist_records INNER JOIN projects USING (project_id) LEFT JOIN users USING (user_id) - WHERE {" AND ".join(conditions)};""", + WHERE {" AND ".join(conditions)} + ORDER BY assist_records.created_at + LIMIT %(p_limit)s OFFSET %(p_start)s;""", params) cur.execute(query) results = helper.list_to_camel_case(cur.fetchall()) diff --git a/ee/api/routers/ee.py b/ee/api/routers/ee.py index 2d4ec8750..9748bd719 100644 --- a/ee/api/routers/ee.py +++ b/ee/api/routers/ee.py @@ -90,5 +90,5 @@ def search_records(projectId: int, data: schemas_ee.AssistRecordSearchPayloadSch @app.get('/{projectId}/assist/records/{recordId}', tags=["assist"]) -def search_records(projectId: int, recordId: int, context: schemas_ee.CurrentContext = Depends(OR_context)): +def get_record(projectId: int, recordId: int, context: schemas_ee.CurrentContext = Depends(OR_context)): return {"data": assist_records.get_record(project_id=projectId, record_id=recordId, context=context)}