Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 expose listing license checkouts for frontend #6987

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions api/specs/web-server/_licensed_items_checkouts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
""" Helper script to generate OAS automatically
"""

# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
# pylint: disable=unused-variable
# pylint: disable=too-many-arguments

from typing import Annotated

from _common import as_query
from fastapi import APIRouter, Depends
from models_library.api_schemas_webserver.licensed_items_purchases import (
LicensedItemPurchaseGet,
)
from models_library.generics import Envelope
from models_library.rest_error import EnvelopedError
from models_library.rest_pagination import Page
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.licenses._exceptions_handlers import _TO_HTTP_ERROR_MAP
from simcore_service_webserver.licenses._licensed_items_checkouts_models import (
LicensedItemCheckoutPathParams,
LicensedItemsCheckoutsListQueryParams,
)
from simcore_service_webserver.wallets._handlers import WalletsPathParams

router = APIRouter(
prefix=f"/{API_VTAG}",
tags=[
"licenses",
],
responses={
i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values()
},
)


@router.get(
"/wallets/{wallet_id}/licensed-items-checkouts",
response_model=Page[LicensedItemPurchaseGet],
tags=["wallets"],
)
async def list_licensed_item_checkouts_for_wallet(
_path: Annotated[WalletsPathParams, Depends()],
_query: Annotated[as_query(LicensedItemsCheckoutsListQueryParams), Depends()],
):
...


@router.get(
"/licensed-items-checkouts/{licensed_item_checkout_id}",
response_model=Envelope[LicensedItemPurchaseGet],
)
async def get_licensed_item_checkout(
_path: Annotated[LicensedItemCheckoutPathParams, Depends()],
):
...
1 change: 1 addition & 0 deletions api/specs/web-server/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"_long_running_tasks",
"_licensed_items",
"_licensed_items_purchases",
"_licensed_items_checkouts",
"_metamodeling",
"_nih_sparc",
"_nih_sparc_redirections",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime
from typing import NamedTuple

from pydantic import PositiveInt
from pydantic import BaseModel, PositiveInt

from ..licensed_items import LicensedItemID
from ..products import ProductName
Expand All @@ -10,8 +10,29 @@
from ..wallets import WalletID
from ._base import OutputSchema

# RPC

class LicensedItemCheckoutGet(OutputSchema):

class LicensedItemCheckoutRpcGet(BaseModel):
licensed_item_checkout_id: LicensedItemCheckoutID
licensed_item_id: LicensedItemID
wallet_id: WalletID
user_id: UserID
product_name: ProductName
started_at: datetime
stopped_at: datetime | None
num_of_seats: int


class LicensedItemCheckoutRpcGetPage(NamedTuple):
items: list[LicensedItemCheckoutRpcGet]
total: PositiveInt


# Rest


class LicensedItemCheckoutRestGet(OutputSchema):
licensed_item_checkout_id: LicensedItemCheckoutID
licensed_item_id: LicensedItemID
wallet_id: WalletID
Expand All @@ -22,6 +43,6 @@ class LicensedItemCheckoutGet(OutputSchema):
num_of_seats: int


class LicensedItemUsageGetPage(NamedTuple):
items: list[LicensedItemCheckoutGet]
class LicensedItemCheckoutRestGetPage(NamedTuple):
items: list[LicensedItemCheckoutRestGet]
total: PositiveInt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
LicensedItemGetPage,
)
from models_library.api_schemas_webserver.licensed_items_checkouts import (
LicensedItemCheckoutGet,
LicensedItemCheckoutRpcGet,
)
from models_library.licensed_items import LicensedItemID
from models_library.products import ProductName
Expand Down Expand Up @@ -78,7 +78,7 @@ async def checkout_licensed_item_for_wallet(
licensed_item_id: LicensedItemID,
num_of_seats: int,
service_run_id: ServiceRunID,
) -> LicensedItemCheckoutGet:
) -> LicensedItemCheckoutRpcGet:
result = await rabbitmq_rpc_client.request(
WEBSERVER_RPC_NAMESPACE,
TypeAdapter(RPCMethodName).validate_python("checkout_licensed_item_for_wallet"),
Expand All @@ -89,7 +89,7 @@ async def checkout_licensed_item_for_wallet(
num_of_seats=num_of_seats,
service_run_id=service_run_id,
)
assert isinstance(result, LicensedItemCheckoutGet) # nosec
assert isinstance(result, LicensedItemCheckoutRpcGet) # nosec
return result


Expand All @@ -100,13 +100,13 @@ async def release_licensed_item_for_wallet(
product_name: ProductName,
user_id: UserID,
licensed_item_checkout_id: LicensedItemCheckoutID,
) -> LicensedItemCheckoutGet:
) -> LicensedItemCheckoutRpcGet:
result = await rabbitmq_rpc_client.request(
WEBSERVER_RPC_NAMESPACE,
TypeAdapter(RPCMethodName).validate_python("release_licensed_item_for_wallet"),
product_name=product_name,
user_id=user_id,
licensed_item_checkout_id=licensed_item_checkout_id,
)
assert isinstance(result, LicensedItemCheckoutGet) # nosec
assert isinstance(result, LicensedItemCheckoutRpcGet) # nosec
return result
Original file line number Diff line number Diff line change
Expand Up @@ -3252,6 +3252,121 @@ paths:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Bad Request
/v0/wallets/{wallet_id}/licensed-items-checkouts:
get:
tags:
- licenses
- wallets
summary: List Licensed Item Checkouts For Wallet
operationId: list_licensed_item_checkouts_for_wallet
parameters:
- name: wallet_id
in: path
required: true
schema:
type: integer
exclusiveMinimum: true
title: Wallet Id
minimum: 0
- name: order_by
in: query
required: false
schema:
type: string
contentMediaType: application/json
contentSchema: {}
default: '{"field":"started_at","direction":"desc"}'
title: Order By
- name: limit
in: query
required: false
schema:
type: integer
default: 20
title: Limit
- name: offset
in: query
required: false
schema:
type: integer
default: 0
title: Offset
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/Page_LicensedItemPurchaseGet_'
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Not Found
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Forbidden
'402':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Payment Required
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Bad Request
/v0/licensed-items-checkouts/{licensed_item_checkout_id}:
get:
tags:
- licenses
summary: Get Licensed Item Checkout
operationId: get_licensed_item_checkout
parameters:
- name: licensed_item_checkout_id
in: path
required: true
schema:
type: string
format: uuid
title: Licensed Item Checkout Id
responses:
'200':
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/Envelope_LicensedItemPurchaseGet_'
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Not Found
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Forbidden
'402':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Payment Required
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/EnvelopedError'
description: Bad Request
/v0/projects/{project_uuid}/checkpoint/{ref_id}/iterations:
get:
tags:
Expand Down
Loading
Loading