11from typing import Annotated , Any
22
3- from fastapi import APIRouter , Depends , status
3+ from fastapi import APIRouter , Depends , HTTPException , status
44from models_library .licensed_items import LicensedItemID
5+ from models_library .resource_tracker_licensed_items_checkouts import (
6+ LicensedItemCheckoutID ,
7+ )
58from pydantic import PositiveInt
9+ from simcore_service_api_server .api .dependencies .resource_usage_tracker_rpc import (
10+ get_resource_usage_tracker_client ,
11+ )
612
713from ...api .dependencies .authentication import get_current_user_id , get_product_name
814from ...api .dependencies .webserver_rpc import get_wb_api_rpc_client
915from ...exceptions .service_errors_utils import DEFAULT_BACKEND_SERVICE_STATUS_CODES
1016from ...models .pagination import Page , PaginationParams
1117from ...models .schemas .model_adapter import LicensedItemCheckoutGet , LicensedItemGet
18+ from ...services_rpc .resource_usage_tracker import ResourceUsageTrackerClient
1219from ...services_rpc .wb_api_server import WbApiRpcClient
1320
1421router = APIRouter ()
@@ -37,7 +44,7 @@ async def get_licensed_items(
3744
3845
3946@router .post (
40- "{licensed_item_id}/release" ,
47+ "{licensed_item_id}/checked_out_items/{licensed_item_checkout_id}/ release" ,
4148 response_model = LicensedItemCheckoutGet ,
4249 status_code = status .HTTP_200_OK ,
4350 responses = _LICENSE_ITEMS_STATUS_CODES ,
@@ -46,12 +53,24 @@ async def get_licensed_items(
4653)
4754async def release_licensed_item (
4855 web_api_rpc : Annotated [WbApiRpcClient , Depends (get_wb_api_rpc_client )],
56+ rut_rpc : Annotated [
57+ ResourceUsageTrackerClient , Depends (get_resource_usage_tracker_client )
58+ ],
4959 product_name : Annotated [str , Depends (get_product_name )],
5060 user_id : Annotated [PositiveInt , Depends (get_current_user_id )],
5161 licensed_item_id : LicensedItemID ,
62+ licensed_item_checkout_id : LicensedItemCheckoutID ,
5263):
64+ _licensed_item_checkout = await rut_rpc .get_licensed_item_checkout (
65+ product_name = product_name , licensed_item_checkout_id = licensed_item_checkout_id
66+ )
67+ if _licensed_item_checkout .licensed_item_id != licensed_item_id :
68+ raise HTTPException (
69+ status_code = status .HTTP_422_UNPROCESSABLE_ENTITY ,
70+ detail = f"{ licensed_item_id } is not the license_item_id associated with the checked out item { licensed_item_checkout_id } " ,
71+ )
5372 return await web_api_rpc .release_licensed_item_for_wallet (
5473 product_name = product_name ,
5574 user_id = user_id ,
56- licensed_item_checkout_id = licensed_item_id ,
75+ licensed_item_checkout_id = licensed_item_checkout_id ,
5776 )
0 commit comments