Skip to content

armgit / mwmbl

Public Imported from GitHub
0

An open source, non-profit web search engine

Specify multiple URLs with repeated query parameters

Daoud Clarkeb32fdbee33ea
diff --git a/mwmbl/platform/api.py b/mwmbl/platform/api.py
index fd945ff..47b217d 100644
--- a/mwmbl/platform/api.py
+++ b/mwmbl/platform/api.py
@@ -189,13 +189,15 @@ def vote_on_search_result(request, vote_request: VoteRequest):
summary="Get vote statistics for search results",
description="Retrieve vote counts (upvotes and downvotes) for one or more URLs in the context of a specific search query. "
"Also returns the current user's vote on each result if they have voted. "
- "URLs should be provided as a comma-separated list.",
+ "URLs should be provided as repeated 'url' query parameters (e.g., ?url=https://example.com&url=https://other.com).",
tags=["Search Result Voting"]
)
-def get_vote_counts(request, query: str, urls: str):
+def get_vote_counts(request, query: str):
check_email_verified(request)
- url_list = [url.strip() for url in urls.split(',') if url.strip()]
+ # Get URLs from repeated query parameters
+ url_list = request.GET.getlist('url')
+ url_list = [u.strip() for u in url_list if u.strip()]
if not url_list:
raise InvalidRequest("At least one URL must be provided.", status=400)
diff --git a/test/test_voting_api.py b/test/test_voting_api.py
index 7b0e8b2..ec16ba8 100644
--- a/test/test_voting_api.py
+++ b/test/test_voting_api.py
@@ -232,7 +232,7 @@ def test_get_vote_counts_single_url(client, verified_user, verified_user2, acces
)
response = client.get(
- f'/api/v1/platform/search-results/votes?query={sample_vote_data["query"]}&urls={sample_vote_data["url"]}',
+ f'/api/v1/platform/search-results/votes?query={sample_vote_data["query"]}&url={sample_vote_data["url"]}',
HTTP_AUTHORIZATION=f'Bearer {access_token}'
)
@@ -269,9 +269,8 @@ def test_get_vote_counts_multiple_urls(client, verified_user, access_token):
vote_type='downvote'
)
- urls_param = f"{url1},{url2}"
response = client.get(
- f'/api/v1/platform/search-results/votes?query={query}&urls={urls_param}',
+ f'/api/v1/platform/search-results/votes?query={query}&url={url1}&url={url2}',
HTTP_AUTHORIZATION=f'Bearer {access_token}'
)
@@ -290,7 +289,7 @@ def test_get_vote_counts_multiple_urls(client, verified_user, access_token):
def test_get_vote_counts_no_urls(client, access_token):
"""Test getting vote counts without providing URLs"""
response = client.get(
- '/api/v1/platform/search-results/votes?query=test&urls=',
+ '/api/v1/platform/search-results/votes?query=test',
HTTP_AUTHORIZATION=f'Bearer {access_token}'
)