-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Introduce vip models pricing 1 of 2 parts (#6897)
- Loading branch information
1 parent
cba896a
commit e05d046
Showing
31 changed files
with
1,424 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" 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, status | ||
from models_library.api_schemas_webserver.licensed_items import LicensedItemGet | ||
from models_library.generics import Envelope | ||
from models_library.rest_error import EnvelopedError | ||
from simcore_service_webserver._meta import API_VTAG | ||
from simcore_service_webserver.catalog.licenses._exceptions_handlers import ( | ||
_TO_HTTP_ERROR_MAP, | ||
) | ||
from simcore_service_webserver.catalog.licenses._models import ( | ||
LicensedItemsBodyParams, | ||
LicensedItemsListQueryParams, | ||
LicensedItemsPathParams, | ||
) | ||
|
||
router = APIRouter( | ||
prefix=f"/{API_VTAG}", | ||
tags=[ | ||
"licenses", | ||
"catalog", | ||
], | ||
responses={ | ||
i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values() | ||
}, | ||
) | ||
|
||
|
||
@router.get( | ||
"/catalog/licensed-items", | ||
response_model=Envelope[list[LicensedItemGet]], | ||
) | ||
async def list_licensed_items( | ||
_query: Annotated[as_query(LicensedItemsListQueryParams), Depends()], | ||
): | ||
... | ||
|
||
|
||
@router.get( | ||
"/catalog/licensed-items/{licensed_item_id}", | ||
response_model=Envelope[LicensedItemGet], | ||
) | ||
async def get_licensed_item( | ||
_path: Annotated[LicensedItemsPathParams, Depends()], | ||
): | ||
... | ||
|
||
|
||
@router.post( | ||
"/catalog/licensed-items/{licensed_item_id}:purchase", | ||
status_code=status.HTTP_204_NO_CONTENT, | ||
) | ||
async def purchase_licensed_item( | ||
_path: Annotated[LicensedItemsPathParams, Depends()], | ||
_body: LicensedItemsBodyParams, | ||
): | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
packages/models-library/src/models_library/api_schemas_webserver/licensed_items.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from datetime import datetime | ||
from typing import NamedTuple | ||
|
||
from models_library.licensed_items import LicensedItemID, LicensedResourceType | ||
from models_library.resource_tracker import PricingPlanId | ||
from pydantic import PositiveInt | ||
|
||
from ._base import OutputSchema | ||
|
||
|
||
class LicensedItemGet(OutputSchema): | ||
licensed_item_id: LicensedItemID | ||
name: str | ||
licensed_resource_type: LicensedResourceType | ||
pricing_plan_id: PricingPlanId | ||
created_at: datetime | ||
modified_at: datetime | ||
|
||
|
||
class LicensedItemGetPage(NamedTuple): | ||
items: list[LicensedItemGet] | ||
total: PositiveInt |
44 changes: 44 additions & 0 deletions
44
packages/models-library/src/models_library/licensed_items.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from datetime import datetime | ||
from enum import auto | ||
from typing import TypeAlias | ||
from uuid import UUID | ||
|
||
from pydantic import BaseModel, ConfigDict, Field | ||
|
||
from .products import ProductName | ||
from .resource_tracker import PricingPlanId | ||
from .utils.enums import StrAutoEnum | ||
|
||
LicensedItemID: TypeAlias = UUID | ||
|
||
|
||
class LicensedResourceType(StrAutoEnum): | ||
VIP_MODEL = auto() | ||
|
||
|
||
# | ||
# DB | ||
# | ||
|
||
|
||
class LicensedItemDB(BaseModel): | ||
licensed_item_id: LicensedItemID | ||
name: str | ||
licensed_resource_type: LicensedResourceType | ||
pricing_plan_id: PricingPlanId | ||
product_name: ProductName | ||
created: datetime = Field( | ||
..., | ||
description="Timestamp on creation", | ||
) | ||
modified: datetime = Field( | ||
..., | ||
description="Timestamp of last modification", | ||
) | ||
# ---- | ||
model_config = ConfigDict(from_attributes=True) | ||
|
||
|
||
class LicensedItemUpdateDB(BaseModel): | ||
name: str | None = None | ||
pricing_plan_id: PricingPlanId | None = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.