Skip to content

Commit

Permalink
Merge pull request #406 from ror-community/org_pagination_with_sort
Browse files Browse the repository at this point in the history
Added default sort for organization api on id field
  • Loading branch information
lizkrznarich authored Sep 19, 2024
2 parents 03e5978 + 9e80c6c commit 3e03b8c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rorapi/common/es_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ def paginate(self, page):

def get_query(self):
return self.search

def add_sort(self, field, order="asc"):
self.search = self.search.sort({field: {"order": order}})
4 changes: 4 additions & 0 deletions rorapi/common/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ def build_search_query(params, version):
]
)

sort_field = params.get("sort", "id")
sort_order = params.get("order", "asc")
qb.add_sort(sort_field, sort_order)

qb.paginate(int(params.get("page", 1)))
return qb.get_query()

Expand Down

0 comments on commit 3e03b8c

Please sign in to comment.