Skip to content

Commit

Permalink
Merge pull request #128 from codeforjapan/fix/posts-id-query
Browse files Browse the repository at this point in the history
fix: クエリパラメータ名称を他エンドポイントとそろえる
  • Loading branch information
yu23ki14 authored Nov 2, 2024
2 parents 6338812 + 71b02bb commit 62a6d39
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions api/birdxplorer_api/routers/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def get_notes(
@router.get("/posts", response_model=PostListResponse)
def get_posts(
request: Request,
post_id: Union[List[PostId], None] = Query(default=None),
note_id: Union[List[NoteId], None] = Query(default=None),
post_ids: Union[List[PostId], None] = Query(default=None),
note_ids: Union[List[NoteId], None] = 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),
Expand All @@ -142,8 +142,8 @@ def get_posts(
created_at_to = ensure_twitter_timestamp(created_at_to)
posts = list(
storage.get_posts(
post_ids=post_id,
note_ids=note_id,
post_ids=post_ids,
note_ids=note_ids,
start=created_at_from,
end=created_at_to,
search_text=search_text,
Expand All @@ -154,8 +154,8 @@ def get_posts(
)
)
total_count = storage.get_number_of_posts(
post_ids=post_id,
note_ids=note_id,
post_ids=post_ids,
note_ids=note_ids,
start=created_at_from,
end=created_at_to,
search_text=search_text,
Expand Down
10 changes: 5 additions & 5 deletions api/tests/routers/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_posts_get_limit_and_offset(client: TestClient, post_samples: List[Post]


def test_posts_get_has_post_id_filter(client: TestClient, post_samples: List[Post]) -> None:
response = client.get(f"/api/v1/data/posts/?postId={post_samples[0].post_id},{post_samples[2].post_id}")
response = client.get(f"/api/v1/data/posts/?postIds={post_samples[0].post_id},{post_samples[2].post_id}")
assert response.status_code == 200
res_json = response.json()
assert res_json == {
Expand All @@ -57,7 +57,7 @@ def test_posts_get_has_post_id_filter(client: TestClient, post_samples: List[Pos


def test_posts_get_has_note_id_filter(client: TestClient, post_samples: List[Post], note_samples: List[Note]) -> None:
response = client.get(f"/api/v1/data/posts/?noteId={','.join([n.note_id for n in note_samples])}")
response = client.get(f"/api/v1/data/posts/?noteIds={','.join([n.note_id for n in note_samples])}")
assert response.status_code == 200
res_json = response.json()
assert res_json == {"data": [json.loads(post_samples[0].model_dump_json())], "meta": {"next": None, "prev": None}}
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_posts_get_timestamp_out_of_range(client: TestClient, post_samples: List


def test_posts_get_with_media_by_default(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?postId=2234567890123456791")
response = client.get("/api/v1/data/posts/?postIds=2234567890123456791")

assert response.status_code == 200
res_json_default = response.json()
Expand All @@ -134,7 +134,7 @@ def test_posts_get_with_media_by_default(client: TestClient, post_samples: List[


def test_posts_get_with_media_true(client: TestClient, post_samples: List[Post]) -> None:
response = client.get("/api/v1/data/posts/?postId=2234567890123456791&media=true")
response = client.get("/api/v1/data/posts/?postIds=2234567890123456791&media=true")

assert response.status_code == 200
res_json_default = response.json()
Expand All @@ -146,7 +146,7 @@ def test_posts_get_with_media_true(client: TestClient, post_samples: List[Post])

def test_posts_get_with_media_false(client: TestClient, post_samples: List[Post]) -> None:
expected_post = post_samples[1].model_copy(update={"media_details": []})
response = client.get("/api/v1/data/posts/?postId=2234567890123456791&media=false")
response = client.get("/api/v1/data/posts/?postIds=2234567890123456791&media=false")

assert response.status_code == 200
res_json_default = response.json()
Expand Down

0 comments on commit 62a6d39

Please sign in to comment.