From f1bbe2986b28bd26ea73ed54ad50e7c1138f96cf Mon Sep 17 00:00:00 2001 From: jasta Date: Sun, 18 Aug 2024 11:05:00 +0900 Subject: [PATCH 1/2] fixes the variable name --- api/birdxplorer_api/routers/data.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/api/birdxplorer_api/routers/data.py b/api/birdxplorer_api/routers/data.py index 9af0e71..92481d9 100644 --- a/api/birdxplorer_api/routers/data.py +++ b/api/birdxplorer_api/routers/data.py @@ -95,8 +95,8 @@ def get_posts( request: Request, post_id: Union[List[PostId], None] = Query(default=None), note_id: Union[List[NoteId], None] = Query(default=None), - created_at_start: Union[None, TwitterTimestamp, str] = Query(default=None), - created_at_end: Union[None, TwitterTimestamp, str] = Query(default=None), + created_at_from: Union[None, TwitterTimestamp, str] = Query(default=None), + created_at_to: Union[None, TwitterTimestamp, str] = Query(default=None), offset: int = Query(default=0, ge=0), limit: int = Query(default=100, gt=0, le=1000), search_text: Union[None, str] = Query(default=None), @@ -107,18 +107,18 @@ def get_posts( posts = list(storage.get_posts_by_ids(post_ids=post_id)) elif note_id is not None: posts = list(storage.get_posts_by_note_ids(note_ids=note_id)) - elif created_at_start is not None: - if created_at_end is not None: + elif created_at_from is not None: + if created_at_to is not None: posts = list( storage.get_posts_by_created_at_range( - start=ensure_twitter_timestamp(created_at_start), - end=ensure_twitter_timestamp(created_at_end), + start=ensure_twitter_timestamp(created_at_from), + end=ensure_twitter_timestamp(created_at_to), ) ) else: - posts = list(storage.get_posts_by_created_at_start(start=ensure_twitter_timestamp(created_at_start))) - elif created_at_end is not None: - posts = list(storage.get_posts_by_created_at_end(end=ensure_twitter_timestamp(created_at_end))) + posts = list(storage.get_posts_by_created_at_start(start=ensure_twitter_timestamp(created_at_from))) + elif created_at_to is not None: + posts = list(storage.get_posts_by_created_at_end(end=ensure_twitter_timestamp(created_at_to))) elif search_text is not None and len(search_text) > 0: posts = list(storage.search_posts_by_text(search_text)) else: From ca07825ea5a94784ca786cfd86951584c3c2a507 Mon Sep 17 00:00:00 2001 From: jasta Date: Sun, 18 Aug 2024 11:29:03 +0900 Subject: [PATCH 2/2] fix: test_data.py updated to pass the tests --- api/tests/routers/test_data.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/tests/routers/test_data.py b/api/tests/routers/test_data.py index baec52b..67160f9 100644 --- a/api/tests/routers/test_data.py +++ b/api/tests/routers/test_data.py @@ -61,14 +61,14 @@ def test_posts_get_has_note_id_filter(client: TestClient, post_samples: List[Pos def test_posts_get_has_created_at_filter_start_and_end(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtStart=2006-7-25 00:00:00&createdAtEnd=2006-7-30 23:59:59") + response = client.get("/api/v1/data/posts/?createdAtFrom=2006-7-25 00:00:00&createdAtTo=2006-7-30 23:59:59") assert response.status_code == 200 res_json = response.json() assert res_json == {"data": [json.loads(post_samples[1].model_dump_json())], "meta": {"next": None, "prev": None}} def test_posts_get_has_created_at_filter_start(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtStart=2006-7-25 00:00:00") + response = client.get("/api/v1/data/posts/?createdAtFrom=2006-7-25 00:00:00") assert response.status_code == 200 res_json = response.json() assert res_json == { @@ -78,7 +78,7 @@ def test_posts_get_has_created_at_filter_start(client: TestClient, post_samples: def test_posts_get_has_created_at_filter_end(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtEnd=2006-7-30 00:00:00") + response = client.get("/api/v1/data/posts/?createdAtTo=2006-7-30 00:00:00") assert response.status_code == 200 res_json = response.json() assert res_json == { @@ -88,14 +88,14 @@ def test_posts_get_has_created_at_filter_end(client: TestClient, post_samples: L def test_posts_get_created_at_range_filter_accepts_integer(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtStart=1153921700000&createdAtEnd=1154921800000") + response = client.get("/api/v1/data/posts/?createdAtFrom=1153921700000&createdAtTo=1154921800000") assert response.status_code == 200 res_json = response.json() assert res_json == {"data": [json.loads(post_samples[1].model_dump_json())], "meta": {"next": None, "prev": None}} def test_posts_get_created_at_start_filter_accepts_integer(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtStart=1153921700000") + response = client.get("/api/v1/data/posts/?createdAtFrom=1153921700000") assert response.status_code == 200 res_json = response.json() assert res_json == { @@ -105,7 +105,7 @@ def test_posts_get_created_at_start_filter_accepts_integer(client: TestClient, p def test_posts_get_created_at_end_filter_accepts_integer(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtEnd=1154921800000") + response = client.get("/api/v1/data/posts/?createdAtTo=1154921800000") assert response.status_code == 200 res_json = response.json() assert res_json == { @@ -115,7 +115,7 @@ def test_posts_get_created_at_end_filter_accepts_integer(client: TestClient, pos def test_posts_get_timestamp_out_of_range(client: TestClient, post_samples: List[Post]) -> None: - response = client.get("/api/v1/data/posts/?createdAtStart=1153921700&createdAtEnd=1153921700") + response = client.get("/api/v1/data/posts/?createdAtFrom=1153921700&createdAtTo=1153921700") assert response.status_code == 422