Skip to content

Commit

Permalink
Fix: reactivate message API time filters (#345)
Browse files Browse the repository at this point in the history
Problem: the time filters are ignored in the messages.json endpoint
since #337.

Solution: reactivate the filtering.
  • Loading branch information
odesenfans committed Mar 21, 2023
1 parent 5ffe81c commit 9c12edc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/aleph/web/controllers/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
LIST_FIELD_SEPARATOR,
Pagination,
cond_output,
make_date_filters,
)

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -175,6 +176,15 @@ class MessageQueryParams(BaseMessageQueryParams):
"a time field lower than this value will be returned.",
)

def to_filter_list(self) -> List[Mapping[str, Any]]:
filters = super().to_filter_list()
date_filters = make_date_filters(
start=self.start_date, end=self.end_date, filter_key="time"
)
if date_filters:
filters.append(date_filters)
return filters


class WsMessageQueryParams(BaseMessageQueryParams):
history: Optional[int] = Field(
Expand Down
2 changes: 1 addition & 1 deletion tests/api/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async def fetch_messages_filter_time_expect_success(
@pytest.mark.asyncio
async def test_time_filters(fixture_messages, ccn_api_client):
# Start and end time specified, should return all messages
start_time, end_time = 164821580, 1648215820
start_time, end_time = 1648215900, 1652126600
messages = await fetch_messages_filter_time_expect_success(
ccn_api_client, start=start_time, end=end_time
)
Expand Down

0 comments on commit 9c12edc

Please sign in to comment.