Skip to content

Commit 96362e2

Browse files
review @pcrespov
1 parent 24d8791 commit 96362e2

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

services/web/server/src/simcore_service_webserver/licenses/_licensed_items_rest.py

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,30 @@ async def purchase_licensed_item(request: web.Request):
8686
path_params = parse_request_path_parameters_as(LicensedItemsPathParams, request)
8787
body_params = await parse_request_body_as(LicensedItemsBodyParams, request)
8888

89-
licensed_item_purchase_get: LicensedItemPurchaseGet = (
90-
await _licensed_items_service.purchase_licensed_item(
91-
app=request.app,
92-
user_id=req_ctx.user_id,
93-
licensed_item_id=path_params.licensed_item_id,
94-
product_name=req_ctx.product_name,
95-
body_params=body_params,
96-
)
89+
purchased_item = await _licensed_items_service.purchase_licensed_item(
90+
app=request.app,
91+
user_id=req_ctx.user_id,
92+
licensed_item_id=path_params.licensed_item_id,
93+
product_name=req_ctx.product_name,
94+
body_params=body_params,
95+
)
96+
97+
output = LicensedItemPurchaseGet(
98+
licensed_item_purchase_id=purchased_item.licensed_item_purchase_id,
99+
product_name=purchased_item.product_name,
100+
licensed_item_id=purchased_item.licensed_item_id,
101+
key=purchased_item.key,
102+
version=purchased_item.version,
103+
wallet_id=purchased_item.wallet_id,
104+
pricing_unit_cost_id=purchased_item.pricing_unit_cost_id,
105+
pricing_unit_cost=purchased_item.pricing_unit_cost,
106+
start_at=purchased_item.start_at,
107+
expire_at=purchased_item.expire_at,
108+
num_of_seats=purchased_item.num_of_seats,
109+
purchased_by_user=purchased_item.purchased_by_user,
110+
user_email=purchased_item.user_email,
111+
purchased_at=purchased_item.purchased_at,
112+
modified_at=purchased_item.modified,
97113
)
98114

99-
return envelope_json_response(licensed_item_purchase_get)
115+
return envelope_json_response(output)

services/web/server/src/simcore_service_webserver/licenses/_licensed_items_service.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44
from datetime import UTC, datetime, timedelta
55

66
from aiohttp import web
7-
from models_library.api_schemas_webserver import (
8-
licensed_items_purchases as webserver_licensed_items_purchases,
7+
8+
# from models_library.api_schemas_webserver import (
9+
# licensed_items_purchases as webserver_licensed_items_purchases,
10+
# )
11+
from models_library.api_schemas_resource_usage_tracker.licensed_items_purchases import (
12+
LicensedItemPurchaseGet,
13+
)
14+
from models_library.licenses import (
15+
LicensedItem,
16+
LicensedItemID,
17+
LicensedItemKey,
18+
LicensedItemPage,
19+
LicensedItemVersion,
920
)
10-
from models_library.licenses import LicensedItem, LicensedItemID, LicensedItemPage
1121
from models_library.products import ProductName
1222
from models_library.resource_tracker_licensed_items_purchases import (
1323
LicensedItemsPurchasesCreate,
@@ -34,8 +44,8 @@
3444
async def get_licensed_item(
3545
app: web.Application,
3646
*,
37-
key: str,
38-
version: str,
47+
key: LicensedItemKey,
48+
version: LicensedItemVersion,
3949
product_name: ProductName,
4050
) -> LicensedItem:
4151

@@ -72,7 +82,7 @@ async def purchase_licensed_item(
7282
user_id: UserID,
7383
licensed_item_id: LicensedItemID,
7484
body_params: LicensedItemsBodyParams,
75-
) -> webserver_licensed_items_purchases.LicensedItemPurchaseGet:
85+
) -> LicensedItemPurchaseGet:
7686
# Check user wallet permissions
7787
wallet = await get_wallet_with_available_credits_by_user_and_wallet(
7888
app, user_id=user_id, wallet_id=body_params.wallet_id, product_name=product_name
@@ -128,23 +138,6 @@ async def purchase_licensed_item(
128138
purchased_at=datetime.now(tz=UTC),
129139
)
130140
rpc_client = get_rabbitmq_rpc_client(app)
131-
purchased_item = await licensed_items_purchases.create_licensed_item_purchase(
141+
return await licensed_items_purchases.create_licensed_item_purchase(
132142
rpc_client, data=_data
133143
)
134-
return webserver_licensed_items_purchases.LicensedItemPurchaseGet(
135-
licensed_item_purchase_id=purchased_item.licensed_item_purchase_id,
136-
product_name=purchased_item.product_name,
137-
licensed_item_id=purchased_item.licensed_item_id,
138-
key=purchased_item.key,
139-
version=purchased_item.version,
140-
wallet_id=purchased_item.wallet_id,
141-
pricing_unit_cost_id=purchased_item.pricing_unit_cost_id,
142-
pricing_unit_cost=purchased_item.pricing_unit_cost,
143-
start_at=purchased_item.start_at,
144-
expire_at=purchased_item.expire_at,
145-
num_of_seats=purchased_item.num_of_seats,
146-
purchased_by_user=purchased_item.purchased_by_user,
147-
user_email=purchased_item.user_email,
148-
purchased_at=purchased_item.purchased_at,
149-
modified_at=purchased_item.modified,
150-
)

0 commit comments

Comments
 (0)