From ae5bdf8970dca42469a3ce0b18672de683255bfc Mon Sep 17 00:00:00 2001 From: Thomas Eidens Date: Fri, 8 Dec 2023 14:54:17 +0100 Subject: [PATCH] Fixed sorting in v2 API --- .../controllers/paper_details_controller.py | 9 ++++++--- neoflask/queries.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/server/swagger_server/controllers/paper_details_controller.py b/api/server/swagger_server/controllers/paper_details_controller.py index d193d732..93620fef 100644 --- a/api/server/swagger_server/controllers/paper_details_controller.py +++ b/api/server/swagger_server/controllers/paper_details_controller.py @@ -50,14 +50,17 @@ def papers_get(reviewed_by=None, query=None, page=None, per_page=None, sort_by=N """ lucene_query = _to_lucene_query(query) if query else None db_page = page - 1 # neo4j pages are 0-indexed, page is checked for > 0 in param validation + db_sort_by = ({ + "preprint-date": "preprint_date", + "reviewing-date": "review_date", + }).get(sort_by) sort_ascending = sort_order == "asc" db_params = dict( reviewed_by=reviewed_by, # parameterized in database query, no need to escape lucene_query=lucene_query, # user input is escaped in _to_lucene_query() page=db_page, # converted from 1- to 0-indexed above - # remaining parameters are already validated and can be passed through - per_page=per_page, - sort_by=sort_by, + per_page=per_page, # already validated, and can be passed through + sort_by=db_sort_by, sort_ascending=sort_ascending ) result = ask_neo(REFEREED_PREPRINTS_V2(), **db_params) diff --git a/neoflask/queries.py b/neoflask/queries.py index cd17a846..b50942a9 100644 --- a/neoflask/queries.py +++ b/neoflask/queries.py @@ -243,7 +243,7 @@ class REFEREED_PREPRINTS_V2(Query): 'reviewed_by': {'req_param': 'reviewed_by', 'default': None}, 'lucene_query': {'req_param': 'lucene_query', 'default': None}, - 'sort_by': {'req_param': 'sort_by', 'default': 'pub_date'}, + 'sort_by': {'req_param': 'sort_by', 'default': 'preprint_date'}, 'sort_ascending': {'req_param': 'sort_ascending', 'default': False}, 'page': {'req_param': 'page', 'default': 0},