Skip to content

Commit fac36e0

Browse files
committed
add implementation for /solvers/{solver_key}/releases/page
1 parent b772784 commit fac36e0

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-19
lines changed

services/api-server/src/simcore_service_api_server/api/routes/solvers.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from ..dependencies.authentication import get_current_user_id, get_product_name
2626
from ..dependencies.services import get_api_client
2727
from ..dependencies.webserver_http import AuthSession, get_webserver_session
28-
from ._common import API_SERVER_DEV_FEATURES_ENABLED
2928
from ._constants import (
3029
FMSG_CHANGELOG_NEW_IN_VERSION,
3130
FMSG_CHANGELOG_REMOVED_IN_VERSION_FORMAT,
@@ -127,7 +126,7 @@ async def get_solvers_page(
127126
description=create_route_description(
128127
base="Lists all released solvers (not just latest version)",
129128
deprecated=True,
130-
alternative="GET /v0/solvers/releases/page",
129+
alternative="GET /v0/solvers/{solver_key}/releases/page",
131130
changelog=[
132131
FMSG_CHANGELOG_NEW_IN_VERSION.format("0.5.0", ""),
133132
FMSG_CHANGELOG_REMOVED_IN_VERSION_FORMAT.format(
@@ -176,19 +175,6 @@ async def list_solvers_releases(
176175
return sorted(all_solvers, key=attrgetter("id", "pep404_version"))
177176

178177

179-
@router.get(
180-
"/releases/page",
181-
response_model=Page[Solver],
182-
include_in_schema=API_SERVER_DEV_FEATURES_ENABLED,
183-
status_code=status.HTTP_501_NOT_IMPLEMENTED,
184-
)
185-
async def get_solvers_releases_page(
186-
page_params: Annotated[PaginationParams, Depends()],
187-
):
188-
msg = f"list solvers releases with pagination={page_params!r}"
189-
raise NotImplementedError(msg)
190-
191-
192178
@router.get(
193179
"/{solver_key:path}/latest",
194180
response_model=Solver,
@@ -257,15 +243,28 @@ async def list_solver_releases(
257243
@router.get(
258244
"/{solver_key:path}/releases/page",
259245
response_model=Page[Solver],
260-
include_in_schema=API_SERVER_DEV_FEATURES_ENABLED,
261-
status_code=status.HTTP_501_NOT_IMPLEMENTED,
262246
)
263247
async def get_solver_releases_page(
264248
solver_key: SolverKeyId,
265249
page_params: Annotated[PaginationParams, Depends()],
250+
user_id: Annotated[int, Depends(get_current_user_id)],
251+
product_name: Annotated[str, Depends(get_product_name)],
252+
solver_service: Annotated[SolverService, Depends(SolverService)],
266253
):
267-
msg = f"list solver {solver_key=} (one) releases with pagination={page_params!r}"
268-
raise NotImplementedError(msg)
254+
solvers, page_meta = await solver_service.solver_release_history(
255+
user_id=user_id,
256+
solver_key=solver_key,
257+
product_name=product_name,
258+
offset=page_params.offset,
259+
limit=page_params.limit,
260+
)
261+
page_params.limit = page_meta.limit
262+
page_params.offset = page_meta.offset
263+
return create_page(
264+
solvers,
265+
total=len(solvers),
266+
params=page_params,
267+
)
269268

270269

271270
@router.get(

services/api-server/tests/unit/api_solvers/test_api_routers_solvers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,16 @@ async def test_list_solver_page_with_mocked_catalog(
117117
response = await client.get(f"/{API_VTAG}/solvers/page", auth=auth)
118118
assert response.status_code == status.HTTP_200_OK
119119
assert len(response.json()["items"]) == response.json()["total"]
120+
121+
122+
async def test_list_solver_releases_page_with_mocked_catalog(
123+
client: httpx.AsyncClient,
124+
mocked_rpc_catalog_service_api: dict,
125+
auth: httpx.BasicAuth,
126+
):
127+
solver_key = "simcore/services/comp/itis/sleeper"
128+
response = await client.get(
129+
f"/{API_VTAG}/solvers/{solver_key}/releases/page", auth=auth
130+
)
131+
assert response.status_code == status.HTTP_200_OK
132+
assert len(response.json()["items"]) == response.json()["total"]

0 commit comments

Comments
 (0)