1
1
from datetime import datetime
2
- from typing import NamedTuple , Self
2
+ from typing import Any , NamedTuple , cast
3
3
4
- from common_library .dict_tools import remap_keys
5
4
from models_library .licensed_items import (
6
- LicensedItemDB ,
5
+ VIP_DETAILS_EXAMPLE ,
7
6
LicensedItemID ,
8
7
LicensedResourceType ,
9
8
)
10
9
from models_library .resource_tracker import PricingPlanId
11
- from pydantic import ConfigDict , PositiveInt
10
+ from models_library .utils .common_validators import to_camel_recursive
11
+ from pydantic import AfterValidator , BaseModel , ConfigDict , PositiveInt
12
+ from pydantic .config import JsonDict
13
+ from typing_extensions import Annotated
12
14
13
15
from ._base import OutputSchema
14
16
17
+ # RPC
15
18
16
- class LicensedItemGet (OutputSchema ):
17
- licensed_item_id : LicensedItemID
18
19
19
- name : str
20
- license_key : str | None
20
+ class LicensedItemRpcGet (BaseModel ):
21
+ licensed_item_id : LicensedItemID
22
+ display_name : str
21
23
licensed_resource_type : LicensedResourceType
24
+ licensed_resource_data : dict [str , Any ]
25
+ pricing_plan_id : PricingPlanId
26
+ created_at : datetime
27
+ modified_at : datetime
28
+ model_config = ConfigDict (
29
+ json_schema_extra = {
30
+ "examples" : [
31
+ {
32
+ "licensed_item_id" : "0362b88b-91f8-4b41-867c-35544ad1f7a1" ,
33
+ "display_name" : "best-model" ,
34
+ "licensed_resource_type" : f"{ LicensedResourceType .VIP_MODEL } " ,
35
+ "licensed_resource_data" : cast (JsonDict , VIP_DETAILS_EXAMPLE ),
36
+ "pricing_plan_id" : "15" ,
37
+ "created_at" : "2024-12-12 09:59:26.422140" ,
38
+ "modified_at" : "2024-12-12 09:59:26.422140" ,
39
+ }
40
+ ]
41
+ },
42
+ )
43
+
44
+
45
+ class LicensedItemRpcGetPage (NamedTuple ):
46
+ items : list [LicensedItemRpcGet ]
47
+ total : PositiveInt
48
+
22
49
50
+ # Rest
51
+
52
+
53
+ class LicensedItemRestGet (OutputSchema ):
54
+ licensed_item_id : LicensedItemID
55
+ display_name : str
56
+ licensed_resource_type : LicensedResourceType
57
+ licensed_resource_data : Annotated [
58
+ dict [str , Any ], AfterValidator (to_camel_recursive )
59
+ ]
23
60
pricing_plan_id : PricingPlanId
24
61
25
62
created_at : datetime
@@ -30,9 +67,9 @@ class LicensedItemGet(OutputSchema):
30
67
"examples" : [
31
68
{
32
69
"licensed_item_id" : "0362b88b-91f8-4b41-867c-35544ad1f7a1" ,
33
- "name" : "best-model" ,
34
- "license_key" : "license-specific-key" ,
70
+ "display_name" : "best-model" ,
35
71
"licensed_resource_type" : f"{ LicensedResourceType .VIP_MODEL } " ,
72
+ "licensed_resource_data" : cast (JsonDict , VIP_DETAILS_EXAMPLE ),
36
73
"pricing_plan_id" : "15" ,
37
74
"created_at" : "2024-12-12 09:59:26.422140" ,
38
75
"modified_at" : "2024-12-12 09:59:26.422140" ,
@@ -41,30 +78,7 @@ class LicensedItemGet(OutputSchema):
41
78
}
42
79
)
43
80
44
- @classmethod
45
- def from_domain_model (cls , licensed_item_db : LicensedItemDB ) -> Self :
46
- return cls .model_validate (
47
- remap_keys (
48
- licensed_item_db .model_dump (
49
- include = {
50
- "licensed_item_id" ,
51
- "licensed_resource_name" ,
52
- "licensed_resource_type" ,
53
- "license_key" ,
54
- "pricing_plan_id" ,
55
- "created" ,
56
- "modified" ,
57
- }
58
- ),
59
- {
60
- "licensed_resource_name" : "name" ,
61
- "created" : "created_at" ,
62
- "modified" : "modified_at" ,
63
- },
64
- )
65
- )
66
-
67
81
68
- class LicensedItemGetPage (NamedTuple ):
69
- items : list [LicensedItemGet ]
82
+ class LicensedItemRestGetPage (NamedTuple ):
83
+ items : list [LicensedItemRestGet ]
70
84
total : PositiveInt
0 commit comments