Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin.py
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | .. http:get:: /api/1/origins/ | ||||
.. warning:: | .. warning:: | ||||
This endpoint used to provide an `origin_from` query parameter, | This endpoint used to provide an `origin_from` query parameter, | ||||
and guarantee an order on results. This is no longer true, | and guarantee an order on results. This is no longer true, | ||||
and only the Link header should be used for paginating through | and only the Link header should be used for paginating through | ||||
results. | results. | ||||
:query int origin_count: The maximum number of origins to return | :query int origin_count: The maximum number of origins to return | ||||
vlorentz: forgot to undo this change | |||||
(default to 100, can not exceed 10000) | (default to 100, can not exceed 10000) | ||||
{return_origin_array} | {return_origin_array} | ||||
{common_headers} | {common_headers} | ||||
{resheader_link} | {resheader_link} | ||||
:statuscode 200: no error | :statuscode 200: no error | ||||
**Example:** | **Example:** | ||||
.. parsed-literal:: | .. parsed-literal:: | ||||
:swh_web_api:`origins?origin_count=500` | :swh_web_api:`origins?origin_count=500` | ||||
Not Done Inline Actionsthis one too (sorry) vlorentz: this one too (sorry) | |||||
Done Inline Actionsdon't be, that's fine it's on me, i looked but fail to see it ;) ardumont: don't be, that's fine
it's on me, i looked but fail to see it ;) | |||||
""" | """ | ||||
origin_from = int(request.query_params.get("origin_from", "1")) | old_param_origin_from = request.query_params.get("origin_from") | ||||
Done Inline ActionsKept origin-from and origin-count which are exposed as is. ardumont: Kept origin-from and origin-count which are exposed as is. | |||||
Not Done Inline ActionsI know, but we should change the name of origin_from because its semantics changed. vlorentz: I know, but we should change the name of `origin_from` because its semantics changed. | |||||
Done Inline Actionsoh yeah, said that prior to you asking me to change I agree, was unsure on how to proceed ;) ardumont: oh yeah, said that prior to you asking me to change
I agree, was unsure on how to proceed ;)
| |||||
origin_count = int(request.query_params.get("origin_count", "100")) | |||||
origin_count = min(origin_count, 10000) | if old_param_origin_from: | ||||
Not Done Inline ActionsThe error message should say to use the Link header. page_token is not part of the API and users shouldn't are about it, as explained in the docstring vlorentz: The error message should say to use the `Link` header. `page_token` is not part of the API and… | |||||
Done Inline Actionsright. ardumont: right. | |||||
results = api_lookup( | raise BadInputExc("Please use the Link header to browse through result") | ||||
service.lookup_origins, | |||||
origin_from, | page_token = request.query_params.get("page_token", None) | ||||
origin_count + 1, | limit = min(int(request.query_params.get("origin_count", "100")), 10000) | ||||
enrich_fn=enrich_origin, | |||||
request=request, | page_result = service.lookup_origins(page_token, limit) | ||||
) | origins = [enrich_origin(o, request=request) for o in page_result.results] | ||||
response = {"results": results, "headers": {}} | next_page_token = page_result.next_page_token | ||||
if len(results) > origin_count: | |||||
origin_from = results.pop()["id"] | response = {"results": origins, "headers": {}} | ||||
if next_page_token is not None: | |||||
Not Done Inline Actionschange the name of the parameter. also raise an error if the old name is passed, so clients who still use it get a proper error vlorentz: change the name of the parameter.
also raise an error if the old name is passed, so clients… | |||||
response["headers"]["link-next"] = reverse( | response["headers"]["link-next"] = reverse( | ||||
"api-1-origins", | "api-1-origins", | ||||
query_params={"origin_from": origin_from, "origin_count": origin_count}, | query_params={"page_token": next_page_token, "origin_count": limit}, | ||||
Not Done Inline Actionshere too vlorentz: here too | |||||
request=request, | request=request, | ||||
) | ) | ||||
for result in results: | |||||
if "id" in result: | |||||
del result["id"] | |||||
return response | return response | ||||
@api_route(r"/origin/(?P<origin_url>.+)/get/", "api-1-origin") | @api_route(r"/origin/(?P<origin_url>.+)/get/", "api-1-origin") | ||||
@api_doc("/origin/") | @api_doc("/origin/") | ||||
@format_docstring(return_origin=DOC_RETURN_ORIGIN) | @format_docstring(return_origin=DOC_RETURN_ORIGIN) | ||||
def api_origin(request, origin_url): | def api_origin(request, origin_url): | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 359 Lines • Show Last 20 Lines |
forgot to undo this change