Skip to content

Commit

Permalink
expose get_available_licensed_items_for_wallet in api-server
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Dec 18, 2024
1 parent c82f397 commit 8a79348
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,24 @@
from typing import Annotated, Any

from fastapi import APIRouter, Depends, status
from fastapi_pagination import Page
from pydantic import PositiveInt
from simcore_service_api_server.api.dependencies.authentication import (
get_current_user_id,
get_product_name,
)
from simcore_service_api_server.api.dependencies.webserver_rpc import (
get_wb_api_rpc_client,
)
from simcore_service_api_server.models.pagination import PaginationParams
from simcore_service_api_server.services_rpc.wb_api_server import WbApiRpcClient

from ...exceptions.service_errors_utils import DEFAULT_BACKEND_SERVICE_STATUS_CODES
from ...models.schemas.errors import ErrorGet
from ...models.schemas.model_adapter import WalletGetWithAvailableCreditsLegacy
from ...models.schemas.model_adapter import (
LicensedItemGet,
WalletGetWithAvailableCreditsLegacy,
)
from ..dependencies.webserver_http import AuthSession, get_webserver_session
from ._constants import FMSG_CHANGELOG_NEW_IN_VERSION

Expand Down Expand Up @@ -49,3 +63,26 @@ async def get_wallet(
webserver_api: Annotated[AuthSession, Depends(get_webserver_session)],
):
return await webserver_api.get_wallet(wallet_id=wallet_id)


@router.get(
"/{wallet_id}/licensed-items",
response_model=Page[LicensedItemGet],
status_code=status.HTTP_200_OK,
responses=WALLET_STATUS_CODES,
description="Get all available licensed items for a given wallet",
include_in_schema=False,
)
async def get_available_licensed_items_for_wallet(
wallet_id: int,
page_params: Annotated[PaginationParams, Depends()],
web_api_rpc: Annotated[WbApiRpcClient, Depends(get_wb_api_rpc_client)],
product_name: Annotated[str, Depends(get_product_name)],
user_id: Annotated[PositiveInt, Depends(get_current_user_id)],
):
return await web_api_rpc.get_available_licensed_items_for_wallet(
product_name=product_name,
wallet_id=wallet_id,
user_id=user_id,
page_params=page_params,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from fastapi import FastAPI
from fastapi_pagination import Page, create_page
from models_library.api_schemas_webserver.licensed_items import LicensedItemGetPage
from models_library.users import UserID
from models_library.wallets import WalletID
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
from servicelib.rabbitmq.rpc_interfaces.webserver.licenses.licensed_items import (
get_available_licensed_items_for_wallet as _get_available_licensed_items_for_wallet,
)
from servicelib.rabbitmq.rpc_interfaces.webserver.licenses.licensed_items import (
get_licensed_items as _get_licensed_items,
)
Expand Down Expand Up @@ -44,7 +49,7 @@ def _create_licensed_items_get_page(

@_exception_mapper(rpc_exception_map={})
async def get_licensed_items(
self, product_name: str, page_params: PaginationParams
self, *, product_name: str, page_params: PaginationParams
) -> Page[LicensedItemGet]:
licensed_items_page = await _get_licensed_items(
rabbitmq_rpc_client=self._client,
Expand All @@ -56,6 +61,26 @@ async def get_licensed_items(
licensed_items_page=licensed_items_page, page_params=page_params
)

@_exception_mapper(rpc_exception_map={})
async def get_available_licensed_items_for_wallet(
self,
product_name: str,
wallet_id: WalletID,
user_id: UserID,
page_params: PaginationParams,
) -> Page[LicensedItemGet]:
licensed_items_page = await _get_available_licensed_items_for_wallet(
rabbitmq_rpc_client=self._client,
product_name=product_name,
wallet_id=wallet_id,
user_id=user_id,
offset=page_params.offset,
limit=page_params.limit,
)
return self._create_licensed_items_get_page(
licensed_items_page=licensed_items_page, page_params=page_params
)


def setup(app: FastAPI, rabbitmq_rmp_client: RabbitMQRPCClient):
app.state.wb_api_rpc_client = WbApiRpcClient(_client=rabbitmq_rmp_client)

0 comments on commit 8a79348

Please sign in to comment.