Skip to content

Commit 250f41a

Browse files
openapi specs
1 parent 99242cc commit 250f41a

File tree

6 files changed

+230
-16
lines changed

6 files changed

+230
-16
lines changed

api/specs/web-server/_resource_usage.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
CreatePricingPlanBodyParams,
2222
CreatePricingUnitBodyParams,
2323
PricingPlanAdminGet,
24+
PricingPlanGet,
2425
PricingPlanToServiceAdminGet,
2526
PricingUnitAdminGet,
2627
PricingUnitGet,
@@ -102,6 +103,29 @@ async def get_pricing_plan_unit(
102103
...
103104

104105

106+
@router.get(
107+
"/pricing-plans",
108+
response_model=Envelope[list[PricingPlanGet]],
109+
summary="List pricing plans",
110+
tags=["pricing-plans"],
111+
description="To keep the listing lightweight, the pricingUnits field is None.",
112+
)
113+
async def list_pricing_plans():
114+
...
115+
116+
117+
@router.get(
118+
"/pricing-plans/{pricing_plan_id}",
119+
response_model=Envelope[PricingPlanGet],
120+
summary="Retrieve detail information about pricing plan",
121+
tags=["pricing-plans"],
122+
)
123+
async def get_pricing_plan(
124+
_path: Annotated[PricingPlanGetPathParams, Depends()],
125+
):
126+
...
127+
128+
105129
## Pricing plans for Admin panel
106130

107131

@@ -112,7 +136,7 @@ async def get_pricing_plan_unit(
112136
tags=["admin"],
113137
description="To keep the listing lightweight, the pricingUnits field is None.",
114138
)
115-
async def list_pricing_plans():
139+
async def list_pricing_plans_for_admin_user():
116140
...
117141

118142

@@ -122,7 +146,7 @@ async def list_pricing_plans():
122146
summary="Retrieve detail information about pricing plan",
123147
tags=["admin"],
124148
)
125-
async def get_pricing_plan(
149+
async def get_pricing_plan_for_admin_user(
126150
_path: Annotated[PricingPlanGetPathParams, Depends()],
127151
):
128152
...

packages/models-library/src/models_library/api_schemas_webserver/resource_usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class PricingPlanGet(OutputSchema):
6060
classification: PricingPlanClassification
6161
created_at: datetime
6262
pricing_plan_key: str
63-
pricing_units: list[PricingUnitGet]
63+
pricing_units: list[PricingUnitGet] | None
6464
is_active: bool
6565

6666

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,13 +5410,49 @@ paths:
54105410
application/json:
54115411
schema:
54125412
$ref: '#/components/schemas/Envelope_PricingUnitGet_'
5413+
/v0/pricing-plans:
5414+
get:
5415+
tags:
5416+
- pricing-plans
5417+
summary: List pricing plans
5418+
description: To keep the listing lightweight, the pricingUnits field is None.
5419+
operationId: list_pricing_plans
5420+
responses:
5421+
'200':
5422+
description: Successful Response
5423+
content:
5424+
application/json:
5425+
schema:
5426+
$ref: '#/components/schemas/Envelope_list_PricingPlanGet__'
5427+
/v0/pricing-plans/{pricing_plan_id}:
5428+
get:
5429+
tags:
5430+
- pricing-plans
5431+
summary: Retrieve detail information about pricing plan
5432+
operationId: get_pricing_plan
5433+
parameters:
5434+
- name: pricing_plan_id
5435+
in: path
5436+
required: true
5437+
schema:
5438+
type: integer
5439+
exclusiveMinimum: true
5440+
title: Pricing Plan Id
5441+
minimum: 0
5442+
responses:
5443+
'200':
5444+
description: Successful Response
5445+
content:
5446+
application/json:
5447+
schema:
5448+
$ref: '#/components/schemas/Envelope_PricingPlanGet_'
54135449
/v0/admin/pricing-plans:
54145450
get:
54155451
tags:
54165452
- admin
54175453
summary: List pricing plans
54185454
description: To keep the listing lightweight, the pricingUnits field is None.
5419-
operationId: list_pricing_plans
5455+
operationId: list_pricing_plans_for_admin_user
54205456
responses:
54215457
'200':
54225458
description: Successful Response
@@ -5447,7 +5483,7 @@ paths:
54475483
tags:
54485484
- admin
54495485
summary: Retrieve detail information about pricing plan
5450-
operationId: get_pricing_plan
5486+
operationId: get_pricing_plan_for_admin_user
54515487
parameters:
54525488
- name: pricing_plan_id
54535489
in: path
@@ -8517,6 +8553,19 @@ components:
85178553
title: Error
85188554
type: object
85198555
title: Envelope[PricingPlanAdminGet]
8556+
Envelope_PricingPlanGet_:
8557+
properties:
8558+
data:
8559+
anyOf:
8560+
- $ref: '#/components/schemas/PricingPlanGet'
8561+
- type: 'null'
8562+
error:
8563+
anyOf:
8564+
- {}
8565+
- type: 'null'
8566+
title: Error
8567+
type: object
8568+
title: Envelope[PricingPlanGet]
85208569
Envelope_PricingPlanToServiceAdminGet_:
85218570
properties:
85228571
data:
@@ -9251,6 +9300,22 @@ components:
92519300
title: Error
92529301
type: object
92539302
title: Envelope[list[PricingPlanAdminGet]]
9303+
Envelope_list_PricingPlanGet__:
9304+
properties:
9305+
data:
9306+
anyOf:
9307+
- items:
9308+
$ref: '#/components/schemas/PricingPlanGet'
9309+
type: array
9310+
- type: 'null'
9311+
title: Data
9312+
error:
9313+
anyOf:
9314+
- {}
9315+
- type: 'null'
9316+
title: Error
9317+
type: object
9318+
title: Envelope[list[PricingPlanGet]]
92549319
Envelope_list_PricingPlanToServiceAdminGet__:
92559320
properties:
92569321
data:
@@ -12317,6 +12382,49 @@ components:
1231712382
- TIER
1231812383
- LICENSE
1231912384
title: PricingPlanClassification
12385+
PricingPlanGet:
12386+
properties:
12387+
pricingPlanId:
12388+
type: integer
12389+
exclusiveMinimum: true
12390+
title: Pricingplanid
12391+
minimum: 0
12392+
displayName:
12393+
type: string
12394+
title: Displayname
12395+
description:
12396+
type: string
12397+
title: Description
12398+
classification:
12399+
$ref: '#/components/schemas/PricingPlanClassification'
12400+
createdAt:
12401+
type: string
12402+
format: date-time
12403+
title: Createdat
12404+
pricingPlanKey:
12405+
type: string
12406+
title: Pricingplankey
12407+
pricingUnits:
12408+
anyOf:
12409+
- items:
12410+
$ref: '#/components/schemas/PricingUnitGet'
12411+
type: array
12412+
- type: 'null'
12413+
title: Pricingunits
12414+
isActive:
12415+
type: boolean
12416+
title: Isactive
12417+
type: object
12418+
required:
12419+
- pricingPlanId
12420+
- displayName
12421+
- description
12422+
- classification
12423+
- createdAt
12424+
- pricingPlanKey
12425+
- pricingUnits
12426+
- isActive
12427+
title: PricingPlanGet
1232012428
PricingPlanToServiceAdminGet:
1232112429
properties:
1232212430
pricingPlanId:

services/web/server/src/simcore_service_webserver/resource_usage/_pricing_plans_admin_handlers.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
PricingUnitWithCostCreate,
2020
PricingUnitWithCostUpdate,
2121
)
22-
from models_library.rest_base import StrictRequestParameters
2322
from pydantic import BaseModel, ConfigDict
2423
from servicelib.aiohttp.requests_validation import (
2524
parse_request_body_as,
@@ -34,6 +33,7 @@
3433
from ..security.decorators import permission_required
3534
from ..utils_aiohttp import envelope_json_response
3635
from . import _pricing_plans_admin_api as admin_api
36+
from ._pricing_plans_models import PricingPlanGetPathParams
3737

3838
#
3939
# API components/schemas
@@ -64,19 +64,14 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
6464
## Admin Pricing Plan endpoints
6565

6666

67-
class PricingPlanGetPathParams(StrictRequestParameters):
68-
pricing_plan_id: PricingPlanId
69-
model_config = ConfigDict(extra="forbid")
70-
71-
7267
@routes.get(
7368
f"/{VTAG}/admin/pricing-plans",
74-
name="list_pricing_plans",
69+
name="list_pricing_plans_for_admin_user",
7570
)
7671
@login_required
7772
@permission_required("resource-usage.write")
7873
@_handle_pricing_plan_admin_exceptions
79-
async def list_pricing_plans(request: web.Request):
74+
async def list_pricing_plans_for_admin_user(request: web.Request):
8075
req_ctx = RequestContext.model_validate(request)
8176

8277
pricing_plans_list = await admin_api.list_pricing_plans(
@@ -102,12 +97,12 @@ async def list_pricing_plans(request: web.Request):
10297

10398
@routes.get(
10499
f"/{VTAG}/admin/pricing-plans/{{pricing_plan_id}}",
105-
name="get_pricing_plan",
100+
name="get_pricing_plan_for_admin_user",
106101
)
107102
@login_required
108103
@permission_required("resource-usage.write")
109104
@_handle_pricing_plan_admin_exceptions
110-
async def get_pricing_plan(request: web.Request):
105+
async def get_pricing_plan_for_admin_user(request: web.Request):
111106
req_ctx = RequestContext.model_validate(request)
112107
path_params = parse_request_path_parameters_as(PricingPlanGetPathParams, request)
113108

services/web/server/src/simcore_service_webserver/resource_usage/_pricing_plans_handlers.py

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import functools
22

33
from aiohttp import web
4-
from models_library.api_schemas_webserver.resource_usage import PricingUnitGet
4+
from models_library.api_schemas_webserver.resource_usage import (
5+
PricingPlanGet,
6+
PricingUnitGet,
7+
)
58
from models_library.resource_tracker import PricingPlanId, PricingUnitId
69
from models_library.rest_base import StrictRequestParameters
710
from servicelib.aiohttp.requests_validation import parse_request_path_parameters_as
@@ -13,7 +16,9 @@
1316
from ..security.decorators import permission_required
1417
from ..utils_aiohttp import envelope_json_response
1518
from ..wallets.errors import WalletAccessForbiddenError
19+
from . import _pricing_plans_admin_api as admin_api
1620
from . import _pricing_plans_api as api
21+
from ._pricing_plans_models import PricingPlanGetPathParams
1722

1823
#
1924
# API components/schemas
@@ -69,3 +74,77 @@ async def get_pricing_plan_unit(request: web.Request):
6974
)
7075

7176
return envelope_json_response(webserver_pricing_unit_get, web.HTTPOk)
77+
78+
79+
@routes.get(
80+
f"/{VTAG}/pricing-plans",
81+
name="list_pricing_plans",
82+
)
83+
@login_required
84+
@permission_required("resource-usage.write")
85+
@_handle_resource_usage_exceptions
86+
async def list_pricing_plans(request: web.Request):
87+
req_ctx = RequestContext.model_validate(request)
88+
89+
pricing_plans_list = await admin_api.list_pricing_plans(
90+
app=request.app,
91+
product_name=req_ctx.product_name,
92+
)
93+
webserver_pricing_unit_get = [
94+
PricingPlanGet(
95+
pricing_plan_id=pricing_plan.pricing_plan_id,
96+
display_name=pricing_plan.display_name,
97+
description=pricing_plan.description,
98+
classification=pricing_plan.classification,
99+
created_at=pricing_plan.created_at,
100+
pricing_plan_key=pricing_plan.pricing_plan_key,
101+
pricing_units=None,
102+
is_active=pricing_plan.is_active,
103+
)
104+
for pricing_plan in pricing_plans_list
105+
]
106+
107+
return envelope_json_response(webserver_pricing_unit_get, web.HTTPOk)
108+
109+
110+
@routes.get(
111+
f"/{VTAG}/pricing-plans/{{pricing_plan_id}}",
112+
name="get_pricing_plan",
113+
)
114+
@login_required
115+
@permission_required("resource-usage.write")
116+
@_handle_resource_usage_exceptions
117+
async def get_pricing_plan(request: web.Request):
118+
req_ctx = RequestContext.model_validate(request)
119+
path_params = parse_request_path_parameters_as(PricingPlanGetPathParams, request)
120+
121+
pricing_plan_get = await admin_api.get_pricing_plan(
122+
app=request.app,
123+
product_name=req_ctx.product_name,
124+
pricing_plan_id=path_params.pricing_plan_id,
125+
)
126+
if pricing_plan_get.pricing_units is None:
127+
msg = "Pricing plan units should not be None"
128+
raise ValueError(msg)
129+
130+
webserver_admin_pricing_plan_get = PricingPlanGet(
131+
pricing_plan_id=pricing_plan_get.pricing_plan_id,
132+
display_name=pricing_plan_get.display_name,
133+
description=pricing_plan_get.description,
134+
classification=pricing_plan_get.classification,
135+
created_at=pricing_plan_get.created_at,
136+
pricing_plan_key=pricing_plan_get.pricing_plan_key,
137+
pricing_units=[
138+
PricingUnitGet(
139+
pricing_unit_id=pricing_unit.pricing_unit_id,
140+
unit_name=pricing_unit.unit_name,
141+
unit_extra_info=pricing_unit.unit_extra_info,
142+
current_cost_per_unit=pricing_unit.current_cost_per_unit,
143+
default=pricing_unit.default,
144+
)
145+
for pricing_unit in pricing_plan_get.pricing_units
146+
],
147+
is_active=pricing_plan_get.is_active,
148+
)
149+
150+
return envelope_json_response(webserver_admin_pricing_plan_get, web.HTTPOk)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from models_library.resource_tracker import PricingPlanId
2+
from models_library.rest_base import StrictRequestParameters
3+
from pydantic import ConfigDict
4+
5+
6+
class PricingPlanGetPathParams(StrictRequestParameters):
7+
pricing_plan_id: PricingPlanId
8+
model_config = ConfigDict(extra="forbid")

0 commit comments

Comments
 (0)