Skip to content

Commit

Permalink
Merge branch 'master' into feature/search-users
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Jan 6, 2025
2 parents eec836a + 61a78bc commit 3d328c8
Show file tree
Hide file tree
Showing 22 changed files with 664 additions and 76 deletions.
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 @@ -9,6 +9,7 @@
from fastapi import APIRouter, Depends, Header, HTTPException, status
from models_library.api_schemas_catalog.services import ServiceGet, ServiceUpdate
from models_library.services import ServiceKey, ServiceType, ServiceVersion
from models_library.services_authoring import Author
from models_library.services_metadata_published import ServiceMetaDataPublished
from pydantic import ValidationError
from pydantic.types import PositiveInt
Expand Down Expand Up @@ -127,7 +128,11 @@ async def list_services(
name="nodetails",
description="nodetails",
type=ServiceType.COMPUTATIONAL,
authors=[{"name": "nodetails", "email": "[email protected]"}],
authors=[
Author.model_construct(
name="nodetails", email="[email protected]"
)
],
contact="[email protected]",
inputs={},
outputs={},
Expand Down
115 changes: 115 additions & 0 deletions services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3278,6 +3278,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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from datetime import datetime
from typing import NamedTuple

from models_library.basic_types import IDStr
from models_library.licensed_items import LicensedItemID
from models_library.products import ProductName
from models_library.resource_tracker_licensed_items_checkouts import (
LicensedItemCheckoutID,
)
from models_library.rest_base import RequestParameters, StrictRequestParameters
from models_library.rest_ordering import (
OrderBy,
OrderDirection,
create_ordering_query_model_class,
)
from models_library.rest_pagination import PageQueryParameters
from models_library.users import UserID
from models_library.wallets import WalletID
from pydantic import BaseModel, PositiveInt


class LicensedItemCheckoutGet(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 LicensedItemCheckoutGetPage(NamedTuple):
items: list[LicensedItemCheckoutGet]
total: PositiveInt


class LicensedItemCheckoutPathParams(StrictRequestParameters):
licensed_item_checkout_id: LicensedItemCheckoutID


_LicensedItemsCheckoutsListOrderQueryParams: type[
RequestParameters
] = create_ordering_query_model_class(
ordering_fields={
"started_at",
},
default=OrderBy(field=IDStr("started_at"), direction=OrderDirection.DESC),
)


class LicensedItemsCheckoutsListQueryParams(
PageQueryParameters,
_LicensedItemsCheckoutsListOrderQueryParams, # type: ignore[misc, valid-type]
):
...
Loading

0 comments on commit 3d328c8

Please sign in to comment.