diff --git a/src/aleph/web/controllers/messages.py b/src/aleph/web/controllers/messages.py index faf64b5f5..d54e70dbe 100644 --- a/src/aleph/web/controllers/messages.py +++ b/src/aleph/web/controllers/messages.py @@ -57,17 +57,21 @@ class BaseMessageQueryParams(BaseModel): sort_by: SortBy = Field( default=SortBy.TIME, + alias="sortBy", description="Key to use to sort the messages. " "'time' uses the message time field. " "'tx-time' uses the first on-chain confirmation time.", ) sort_order: SortOrder = Field( default=SortOrder.DESCENDING, + alias="sortOrder", description="Order in which messages should be listed: " "-1 means most recent messages first, 1 means older messages first.", ) message_type: Optional[MessageType] = Field( - default=None, alias="msgType", description="Message type. Deprecated: use msgTypes instead" + default=None, + alias="msgType", + description="Message type. Deprecated: use msgTypes instead", ) message_types: Optional[List[MessageType]] = Field( default=None, alias="msgTypes", description="Accepted message types." diff --git a/src/aleph/web/controllers/posts.py b/src/aleph/web/controllers/posts.py index 70cbd57f9..13a25d574 100644 --- a/src/aleph/web/controllers/posts.py +++ b/src/aleph/web/controllers/posts.py @@ -70,12 +70,14 @@ class PostQueryParams(BaseModel): ) sort_by: SortBy = Field( default=SortBy.TIME, + alias="sortBy", description="Key to use to sort the posts. " "'time' uses the post creation time field. " "'tx-time' uses the first on-chain confirmation time.", ) sort_order: SortOrder = Field( default=SortOrder.DESCENDING, + alias="sortOrder", description="Order in which messages should be listed: " "-1 means most recent messages first, 1 means older messages first.", ) diff --git a/tests/api/test_list_messages.py b/tests/api/test_list_messages.py index 8e81f8ad7..668b36df8 100644 --- a/tests/api/test_list_messages.py +++ b/tests/api/test_list_messages.py @@ -272,8 +272,8 @@ async def fetch_messages_filter_time( ) -> aiohttp.ClientResponse: params: Dict[str, Union[float, int, str]] = { - "sort_by": sort_by, - "sort_order": sort_order, + "sortBy": sort_by, + "sortOrder": sort_order, } if start: params["startDate"] = start @@ -373,7 +373,7 @@ async def fetch_messages_with_pagination( ): return await api_client.get( MESSAGES_URI, - params={"page": page, "pagination": pagination, "sort_order": sort_order}, + params={"page": page, "pagination": pagination, "sortOrder": sort_order}, ) @@ -465,18 +465,15 @@ def get_confirmed_time(msg: Dict) -> Tuple[float, float]: # Return a high timestamp to make unconfirmed messages last return dt.datetime(3000, 1, 1).timestamp(), msg["time"] - sorted_messages_by_time = sorted(fixture_messages, key=get_confirmed_time) + sorted_messages_by_time = list( + sorted(fixture_messages, key=get_confirmed_time, reverse=sort_order == -1) + ) - # Descending order messages = await fetch_messages_filter_time_expect_success( ccn_api_client, sort_by="tx-time", sort_order=sort_order ) assert_messages_equal(messages=messages, expected_messages=sorted_messages_by_time) - if sort_order == -1: - # Note: list() is used for mypy - sorted_messages_by_time = list(reversed(sorted_messages_by_time)) - assert [msg["item_hash"] for msg in messages] == [ msg["item_hash"] for msg in sorted_messages_by_time ]