Skip to content

Commit

Permalink
start developing an webapi rpc client
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Dec 12, 2024
1 parent a41e126 commit deed91a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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,
Expand Down Expand Up @@ -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()
)
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit deed91a

Please sign in to comment.