Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DA-4204] Adding Pagination to workbench/audit/workspace/snapshots API #3853

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions rdr_service/api/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@


DEFAULT_MAX_RESULTS = 100
MAX_MAX_RESULTS = 10000


def log_api_request(log: RequestsLog = None, model_obj=None):
Expand Down Expand Up @@ -130,6 +129,7 @@ class BaseApi(Resource, ApiUtilMixin):
def __init__(self, dao, get_returns_children=False):
self.dao = dao
self._get_returns_children = get_returns_children
self.max_max_results = 10000

def _get_request_arg_bool(self, key, default=False):
"""
Expand Down Expand Up @@ -280,8 +280,8 @@ def _make_query(self, check_invalid=False):
max_results = int(request.args["_count"])
if max_results < 1:
raise BadRequest("_count < 1")
if max_results > MAX_MAX_RESULTS:
raise BadRequest("_count exceeds {}".format(MAX_MAX_RESULTS))
if max_results > self.max_max_results:
raise BadRequest("_count exceeds {}".format(self.max_max_results))
elif key == "_token":
pagination_token = value
elif key == "_sort" or key == "_sort:asc":
Expand Down
18 changes: 17 additions & 1 deletion rdr_service/api/redcap_workbench_audit_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BaseRedcapApi(BaseApi):
def __init__(self):
super().__init__(WorkbenchWorkspaceAuditDao())
self.get_filters = None
self.max_max_results = 6000

@auth_required(REDCAP_AND_RDR)
def get(self):
Expand Down Expand Up @@ -58,7 +59,16 @@ def __init__(self):

def get(self):
super(RedcapWorkbenchAuditApi, self).get()
return self.dao.workspace_dao.get_redcap_audit_workspaces(**self.get_filters)

# No pagination required, response always contains a single record
if self.get_filters.get('snapshot_id') is not None or self.get_filters.get('workspace_id') is not None:
return self.dao.workspace_dao.get_redcap_audit_workspaces(self.get_filters.get('snapshot_id'),
self.get_filters.get('workspace_id'))
# Pagination is required for last_snapshot_id and returning all snapshots
if self.get_filters.get('last_snapshot_id') is not None:
self.dao.workspace_dao.last_snapshot_id = self.get_filters.get('last_snapshot_id')
response = self._query("snapshotId")
return response

def _do_insert(self, m):
audit_records = super()._do_insert(m)
Expand All @@ -77,6 +87,12 @@ def _do_insert(self, m):
in_seconds=30, queue='resource-rebuild')
return audit_records

@classmethod
def _make_resource_url(cls, response_json, id_field, participant_id):
from rdr_service import main
url = main.api.url_for(cls, snapshot_id=response_json[0][id_field], _external=True)
return url

class RedcapResearcherAuditApi(BaseRedcapApi):
def __init__(self):
super().__init__()
Expand Down
Loading