From deed91a9bf021803aaae7cd5fae5bc715c57d919 Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Thu, 12 Dec 2024 06:59:02 +0100 Subject: [PATCH] start developing an webapi rpc client --- .../api/routes/licensed_items.py | 5 +++ .../models/schemas/model_adapter.py | 21 ++++++++++++ .../services_rpc/wb_api_server.py | 33 +++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 services/api-server/src/simcore_service_api_server/services_rpc/wb_api_server.py diff --git a/services/api-server/src/simcore_service_api_server/api/routes/licensed_items.py b/services/api-server/src/simcore_service_api_server/api/routes/licensed_items.py index 8574be2a1b0..5f40440fa8a 100644 --- a/services/api-server/src/simcore_service_api_server/api/routes/licensed_items.py +++ b/services/api-server/src/simcore_service_api_server/api/routes/licensed_items.py @@ -6,7 +6,9 @@ from servicelib.rabbitmq.rpc_interfaces.webserver.licenses.licensed_items import ( get_licensed_items as _get_licensed_items, ) +from simcore_service_api_server.api.dependencies.authentication import get_product_name from simcore_service_api_server.api.dependencies.rabbitmq import get_rabbitmq_rpc_client +from simcore_service_api_server.models.pagination import PaginationParams router = APIRouter() @@ -16,8 +18,11 @@ ) async def get_licensed_items( wallet_id: int, + page_params: Annotated[PaginationParams, Depends()], webserver_rpc_api: Annotated[RabbitMQRPCClient, Depends(get_rabbitmq_rpc_client)], + product_name: Annotated[str, Depends(get_product_name)], ) -> LicensedItemGetPage: return await _get_licensed_items( rabbitmq_rpc_client=webserver_rpc_api, + product_name=product_name, ) diff --git a/services/api-server/src/simcore_service_api_server/models/schemas/model_adapter.py b/services/api-server/src/simcore_service_api_server/models/schemas/model_adapter.py index 3b88cd82ef7..17a76df3ff8 100644 --- a/services/api-server/src/simcore_service_api_server/models/schemas/model_adapter.py +++ b/services/api-server/src/simcore_service_api_server/models/schemas/model_adapter.py @@ -7,6 +7,9 @@ from models_library.api_schemas_api_server.pricing_plans import ( ServicePricingPlanGet as _ServicePricingPlanGet, ) +from models_library.api_schemas_webserver.licensed_items import ( + LicensedItemGet as _LicensedItemGet, +) from models_library.api_schemas_webserver.product import ( GetCreditPrice as _GetCreditPrice, ) @@ -18,6 +21,7 @@ ) from models_library.basic_types import IDStr, NonNegativeDecimal from models_library.groups import GroupID +from models_library.licensed_items import LicensedItemID, LicensedResourceType from models_library.resource_tracker import ( PricingPlanClassification, PricingPlanId, @@ -121,3 +125,20 @@ class ServicePricingPlanGetLegacy(BaseModel): assert set(ServicePricingPlanGetLegacy.model_fields.keys()) == set( _ServicePricingPlanGet.model_fields.keys() ) + + +class LicensedItemGet(BaseModel): + model_config = ConfigDict( + populate_by_name=True, + ) + licensed_item_id: LicensedItemID + name: str + licensed_resource_type: LicensedResourceType + pricing_plan_id: PricingPlanId + created_at: datetime + modified_at: datetime + + +assert set(LicensedItemGet.model_fields.keys()) == set( + _LicensedItemGet.model_fields.keys() +) diff --git a/services/api-server/src/simcore_service_api_server/services_rpc/wb_api_server.py b/services/api-server/src/simcore_service_api_server/services_rpc/wb_api_server.py new file mode 100644 index 00000000000..8988185b5ac --- /dev/null +++ b/services/api-server/src/simcore_service_api_server/services_rpc/wb_api_server.py @@ -0,0 +1,33 @@ +from dataclasses import dataclass + +from fastapi_pagination import Page, create_page +from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient +from servicelib.rabbitmq.rpc_interfaces.webserver.licenses.licensed_items import ( + get_licensed_items as _get_licensed_items, +) +from simcore_service_api_server.models.pagination import PaginationParams + +from ..models.schemas.model_adapter import LicensedItemGet + + +@dataclass +class WbApiRpcClient: + _rabbitmq_rpc_client: RabbitMQRPCClient + + async def get_licensed_items( + self, product_name: str, page_params: PaginationParams + ) -> Page[LicensedItemGet]: + licensed_items_page = await _get_licensed_items( + rabbitmq_rpc_client=self._rabbitmq_rpc_client, + product_name=product_name, + offset=page_params.offset, + limit=page_params.limit, + ) + return create_page( + [ + LicensedItemGet.model_validate(elm.model_dump()) + for elm in licensed_items_page.items + ], + total=licensed_items_page.total, + params=page_params, + )