Skip to content

Commit 2d40f7b

Browse files
committed
models
1 parent 702bde9 commit 2d40f7b

File tree

5 files changed

+67
-57
lines changed

5 files changed

+67
-57
lines changed

api/specs/web-server/_catalog.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
from models_library.generics import Envelope
1616
from models_library.rest_pagination import Page
1717
from simcore_service_webserver._meta import API_VTAG
18-
from simcore_service_webserver.catalog._controller_rest import (
18+
from simcore_service_webserver.catalog._controller_rest_schemas import (
19+
FromServiceOutputQueryParams,
1920
ListServiceParams,
21+
ServiceInputsPathParams,
22+
ServiceOutputsPathParams,
2023
ServicePathParams,
21-
_FromServiceOutputParams,
22-
_ServiceInputsPathParams,
23-
_ServiceOutputsPathParams,
24-
_ToServiceInputsParams,
24+
ToServiceInputsQueryParams,
2525
)
2626

2727
router = APIRouter(
@@ -71,7 +71,7 @@ def list_service_inputs(
7171
response_model=Envelope[ServiceInputGet],
7272
)
7373
def get_service_input(
74-
_path: Annotated[_ServiceInputsPathParams, Depends()],
74+
_path: Annotated[ServiceInputsPathParams, Depends()],
7575
): ...
7676

7777

@@ -81,7 +81,7 @@ def get_service_input(
8181
)
8282
def get_compatible_inputs_given_source_output(
8383
_path: Annotated[ServicePathParams, Depends()],
84-
_query: Annotated[_FromServiceOutputParams, Depends()],
84+
_query: Annotated[FromServiceOutputQueryParams, Depends()],
8585
): ...
8686

8787

@@ -99,7 +99,7 @@ def list_service_outputs(
9999
response_model=Envelope[list[ServiceOutputGet]],
100100
)
101101
def get_service_output(
102-
_path: Annotated[_ServiceOutputsPathParams, Depends()],
102+
_path: Annotated[ServiceOutputsPathParams, Depends()],
103103
): ...
104104

105105

@@ -109,7 +109,7 @@ def get_service_output(
109109
)
110110
def get_compatible_outputs_given_target_input(
111111
_path: Annotated[ServicePathParams, Depends()],
112-
_query: Annotated[_ToServiceInputsParams, Depends()],
112+
_query: Annotated[ToServiceInputsQueryParams, Depends()],
113113
): ...
114114

115115

packages/models-library/src/models_library/rest_pagination.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
int, Field(ge=1, lt=MAXIMUM_NUMBER_OF_ITEMS_PER_PAGE)
2727
]
2828

29+
PageOffsetInt: TypeAlias = NonNegativeInt
30+
2931
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE: Final[PageLimitInt] = TypeAdapter(
3032
PageLimitInt
3133
).validate_python(20)
@@ -51,15 +53,19 @@ class CursorQueryParameters(RequestParameters):
5153
class PageQueryParameters(RequestParameters):
5254
"""Use as pagination options in query parameters"""
5355

54-
limit: PageLimitInt = Field(
55-
default=TypeAdapter(PageLimitInt).validate_python(
56-
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE
56+
limit: Annotated[
57+
PageLimitInt,
58+
Field(
59+
default=TypeAdapter(PageLimitInt).validate_python(
60+
DEFAULT_NUMBER_OF_ITEMS_PER_PAGE
61+
),
62+
description="maximum number of items to return (pagination)",
5763
),
58-
description="maximum number of items to return (pagination)",
59-
)
60-
offset: NonNegativeInt = Field(
61-
default=0, description="index to the first item to return (pagination)"
62-
)
64+
]
65+
offset: Annotated[
66+
PageOffsetInt,
67+
Field(default=0, description="index to the first item to return (pagination)"),
68+
]
6369

6470

6571
class PageMetaInfoLimitOffset(BaseModel):
@@ -120,8 +126,7 @@ class PageLinks(
120126
BeforeValidator(lambda x: str(TypeAdapter(AnyHttpUrl).validate_python(x))),
121127
]
122128
]
123-
):
124-
...
129+
): ...
125130

126131

127132
ItemT = TypeVar("ItemT")

services/web/server/src/simcore_service_webserver/catalog/_controller_rest.py

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,14 @@
1414
from models_library.api_schemas_webserver.catalog import (
1515
CatalogServiceGet,
1616
CatalogServiceUpdate,
17-
ServiceInputKey,
18-
ServiceOutputKey,
1917
)
2018
from models_library.api_schemas_webserver.resource_usage import PricingPlanGet
21-
from models_library.rest_pagination import Page, PageQueryParameters
19+
from models_library.rest_pagination import Page
2220
from models_library.rest_pagination_utils import paginate_data
23-
from models_library.services import ServiceKey, ServiceVersion
2421
from models_library.services_resources import (
2522
ServiceResourcesDict,
2623
ServiceResourcesDictHelpers,
2724
)
28-
from pydantic import BaseModel, Field
2925
from servicelib.aiohttp.requests_validation import (
3026
parse_request_body_as,
3127
parse_request_path_parameters_as,
@@ -45,9 +41,13 @@
4541
)
4642
from ._controller_rest_schemas import (
4743
CatalogRequestContext,
44+
FromServiceOutputQueryParams,
4845
ListServiceParams,
46+
ServiceInputsPathParams,
47+
ServiceOutputsPathParams,
4948
ServicePathParams,
5049
ServiceTagPathParams,
50+
ToServiceInputsQueryParams,
5151
)
5252

5353
_logger = logging.getLogger(__name__)
@@ -76,9 +76,8 @@ async def list_services_latest(request: Request):
7676
user_id=request_ctx.user_id,
7777
product_name=request_ctx.product_name,
7878
unit_registry=request_ctx.unit_registry,
79-
page_params=PageQueryParameters.model_construct(
80-
offset=query_params.offset, limit=query_params.limit
81-
),
79+
offset=query_params.offset,
80+
limit=query_params.limit,
8281
)
8382

8483
assert page_meta.limit == query_params.limit # nosec
@@ -174,10 +173,6 @@ async def list_service_inputs(request: Request):
174173
)
175174

176175

177-
class _ServiceInputsPathParams(ServicePathParams):
178-
input_key: ServiceInputKey
179-
180-
181176
@routes.get(
182177
f"{VTAG}/catalog/services/{{service_key}}/{{service_version}}/inputs/{{input_key}}",
183178
name="get_service_input",
@@ -186,7 +181,7 @@ class _ServiceInputsPathParams(ServicePathParams):
186181
@permission_required("services.catalog.*")
187182
async def get_service_input(request: Request):
188183
ctx = CatalogRequestContext.create(request)
189-
path_params = parse_request_path_parameters_as(_ServiceInputsPathParams, request)
184+
path_params = parse_request_path_parameters_as(ServiceInputsPathParams, request)
190185

191186
# Evaluate and return validated model
192187
response_model = await _service.get_service_input(
@@ -202,12 +197,6 @@ async def get_service_input(request: Request):
202197
)
203198

204199

205-
class _FromServiceOutputParams(BaseModel):
206-
from_service_key: ServiceKey = Field(..., alias="fromService")
207-
from_service_version: ServiceVersion = Field(..., alias="fromVersion")
208-
from_output_key: ServiceOutputKey = Field(..., alias="fromOutput")
209-
210-
211200
@routes.get(
212201
f"{VTAG}/catalog/services/{{service_key}}/{{service_version}}/inputs:match",
213202
name="get_compatible_inputs_given_source_output",
@@ -217,8 +206,8 @@ class _FromServiceOutputParams(BaseModel):
217206
async def get_compatible_inputs_given_source_output(request: Request):
218207
ctx = CatalogRequestContext.create(request)
219208
path_params = parse_request_path_parameters_as(ServicePathParams, request)
220-
query_params: _FromServiceOutputParams = parse_request_query_parameters_as(
221-
_FromServiceOutputParams, request
209+
query_params: FromServiceOutputQueryParams = parse_request_query_parameters_as(
210+
FromServiceOutputQueryParams, request
222211
)
223212

224213
# Evaluate and return validated model
@@ -257,10 +246,6 @@ async def list_service_outputs(request: Request):
257246
)
258247

259248

260-
class _ServiceOutputsPathParams(ServicePathParams):
261-
output_key: ServiceOutputKey
262-
263-
264249
@routes.get(
265250
f"{VTAG}/catalog/services/{{service_key}}/{{service_version}}/outputs/{{output_key}}",
266251
name="get_service_output",
@@ -269,7 +254,7 @@ class _ServiceOutputsPathParams(ServicePathParams):
269254
@permission_required("services.catalog.*")
270255
async def get_service_output(request: Request):
271256
ctx = CatalogRequestContext.create(request)
272-
path_params = parse_request_path_parameters_as(_ServiceOutputsPathParams, request)
257+
path_params = parse_request_path_parameters_as(ServiceOutputsPathParams, request)
273258

274259
# Evaluate and return validated model
275260
response_model = await _service.get_service_output(
@@ -285,12 +270,6 @@ async def get_service_output(request: Request):
285270
)
286271

287272

288-
class _ToServiceInputsParams(BaseModel):
289-
to_service_key: ServiceKey = Field(..., alias="toService")
290-
to_service_version: ServiceVersion = Field(..., alias="toVersion")
291-
to_input_key: ServiceInputKey = Field(..., alias="toInput")
292-
293-
294273
@routes.get(
295274
f"{VTAG}/catalog/services/{{service_key}}/{{service_version}}/outputs:match",
296275
name="get_compatible_outputs_given_target_input",
@@ -305,8 +284,8 @@ async def get_compatible_outputs_given_target_input(request: Request):
305284
"""
306285
ctx = CatalogRequestContext.create(request)
307286
path_params = parse_request_path_parameters_as(ServicePathParams, request)
308-
query_params: _ToServiceInputsParams = parse_request_query_parameters_as(
309-
_ToServiceInputsParams, request
287+
query_params: ToServiceInputsQueryParams = parse_request_query_parameters_as(
288+
ToServiceInputsQueryParams, request
310289
)
311290

312291
data = await _service.get_compatible_outputs_given_target_input(

services/web/server/src/simcore_service_webserver/catalog/_controller_rest_schemas.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pydantic import (
2222
BaseModel,
2323
ConfigDict,
24+
Field,
2425
field_validator,
2526
)
2627
from servicelib.aiohttp.requests_validation import handle_validation_as_http_error
@@ -192,3 +193,23 @@ class ListServiceParams(PageQueryParameters): ...
192193

193194
class ServiceTagPathParams(ServicePathParams):
194195
tag_id: IdInt
196+
197+
198+
class ServiceInputsPathParams(ServicePathParams):
199+
input_key: ServiceInputKey
200+
201+
202+
class FromServiceOutputQueryParams(BaseModel):
203+
from_service_key: ServiceKey = Field(..., alias="fromService")
204+
from_service_version: ServiceVersion = Field(..., alias="fromVersion")
205+
from_output_key: ServiceOutputKey = Field(..., alias="fromOutput")
206+
207+
208+
class ServiceOutputsPathParams(ServicePathParams):
209+
output_key: ServiceOutputKey
210+
211+
212+
class ToServiceInputsQueryParams(BaseModel):
213+
to_service_key: ServiceKey = Field(..., alias="toService")
214+
to_service_version: ServiceVersion = Field(..., alias="toVersion")
215+
to_input_key: ServiceInputKey = Field(..., alias="toInput")

services/web/server/src/simcore_service_webserver/catalog/_service.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
ServiceOutputKey,
1212
)
1313
from models_library.products import ProductName
14-
from models_library.rest_pagination import PageMetaInfoLimitOffset, PageQueryParameters
14+
from models_library.rest_pagination import (
15+
PageLimitInt,
16+
PageMetaInfoLimitOffset,
17+
PageOffsetInt,
18+
)
1519
from models_library.services import (
1620
ServiceInput,
1721
ServiceKey,
@@ -67,16 +71,17 @@ async def list_latest_services(
6771
user_id: UserID,
6872
product_name: ProductName,
6973
unit_registry: UnitRegistry,
70-
page_params: PageQueryParameters,
74+
limit: PageLimitInt,
75+
offset: PageOffsetInt,
7176
) -> tuple[list, PageMetaInfoLimitOffset]:
7277
# NOTE: will replace list_services
7378

7479
page = await catalog_rpc.list_services_paginated(
7580
get_rabbitmq_rpc_client(app),
7681
product_name=product_name,
7782
user_id=user_id,
78-
limit=page_params.limit,
79-
offset=page_params.offset,
83+
limit=limit,
84+
offset=offset,
8085
)
8186

8287
page_data = jsonable_encoder(page.data, exclude_unset=True)

0 commit comments

Comments
 (0)