https://dev.kronoz.win/r/marzneshin.git
| 1 |
ee1351a |
Dawsh |
2y ago |
from typing import List, Optional |
| 2 |
a47eb4c |
Dawsh |
2y ago |
|
| 3 |
ee1351a |
Dawsh |
2y ago |
from pydantic import ConfigDict, BaseModel, Field, computed_field |
| 4 |
a47eb4c |
Dawsh |
2y ago |
|
| 5 |
a47eb4c |
Dawsh |
2y ago |
|
| 6 |
a47eb4c |
Dawsh |
2y ago |
class ServiceBase(BaseModel): |
| 7 |
a47eb4c |
Dawsh |
2y ago |
id: Optional[int] = None |
| 8 |
912788f |
Mardin |
2y ago |
name: Optional[str] = Field(None) |
| 9 |
a47eb4c |
Dawsh |
2y ago |
model_config = ConfigDict(from_attributes=True) |
| 10 |
a47eb4c |
Dawsh |
2y ago |
|
| 11 |
912788f |
Mardin |
2y ago |
|
| 12 |
a47eb4c |
Dawsh |
2y ago |
from app.models.proxy import InboundBase |
| 13 |
a47eb4c |
Dawsh |
2y ago |
from app.models.user import UserBase |
| 14 |
a47eb4c |
Dawsh |
2y ago |
|
| 15 |
912788f |
Mardin |
2y ago |
|
| 16 |
a47eb4c |
Dawsh |
2y ago |
class Service(ServiceBase): |
| 17 |
a47eb4c |
Dawsh |
2y ago |
users: List[UserBase] = Field([]) |
| 18 |
a47eb4c |
Dawsh |
2y ago |
inbounds: List[InboundBase] = Field([]) |
| 19 |
a47eb4c |
Dawsh |
2y ago |
|
| 20 |
a47eb4c |
Dawsh |
2y ago |
|
| 21 |
ee1351a |
Dawsh |
2y ago |
class ServiceCreate(ServiceBase): |
| 22 |
a47eb4c |
Dawsh |
2y ago |
users: List[int] = Field([]) |
| 23 |
a47eb4c |
Dawsh |
2y ago |
inbounds: List[int] = Field([]) |
| 24 |
a47eb4c |
Dawsh |
2y ago |
model_config = ConfigDict(json_schema_extra={ |
| 25 |
a47eb4c |
Dawsh |
2y ago |
"example": { |
| 26 |
a47eb4c |
Dawsh |
2y ago |
"name": "my service 1", |
| 27 |
a47eb4c |
Dawsh |
2y ago |
"inbounds": [1, 5, 9], |
| 28 |
a47eb4c |
Dawsh |
2y ago |
"users": [1, 2, 3] |
| 29 |
a47eb4c |
Dawsh |
2y ago |
} |
| 30 |
a47eb4c |
Dawsh |
2y ago |
}) |
| 31 |
a47eb4c |
Dawsh |
2y ago |
|
| 32 |
a47eb4c |
Dawsh |
2y ago |
|
| 33 |
ee1351a |
Dawsh |
2y ago |
class ServiceModify(ServiceBase): |
| 34 |
ee1351a |
Dawsh |
2y ago |
inbounds: Optional[List[int]] = Field(None) |
| 35 |
a47eb4c |
Dawsh |
2y ago |
model_config = ConfigDict(json_schema_extra={ |
| 36 |
a47eb4c |
Dawsh |
2y ago |
"example": { |
| 37 |
a47eb4c |
Dawsh |
2y ago |
"id": 2, |
| 38 |
a47eb4c |
Dawsh |
2y ago |
"name": "my service 2", |
| 39 |
ee1351a |
Dawsh |
2y ago |
"inbounds": [1, 2, 3] |
| 40 |
a47eb4c |
Dawsh |
2y ago |
} |
| 41 |
a47eb4c |
Dawsh |
2y ago |
}) |
| 42 |
a47eb4c |
Dawsh |
2y ago |
|
| 43 |
a47eb4c |
Dawsh |
2y ago |
|
| 44 |
a47eb4c |
Dawsh |
2y ago |
class ServiceResponse(Service): |
| 45 |
a47eb4c |
Dawsh |
2y ago |
id: int |
| 46 |
e72f150 |
Dawsh |
2y ago |
|
| 47 |
e72f150 |
Dawsh |
2y ago |
@computed_field |
| 48 |
e72f150 |
Dawsh |
2y ago |
@property |
| 49 |
e72f150 |
Dawsh |
2y ago |
def user_ids(self) -> List[int]: |
| 50 |
912788f |
Mardin |
2y ago |
return [u.id for u in self.users] |
| 51 |
e72f150 |
Dawsh |
2y ago |
|
| 52 |
e72f150 |
Dawsh |
2y ago |
@computed_field |
| 53 |
e72f150 |
Dawsh |
2y ago |
@property |
| 54 |
e72f150 |
Dawsh |
2y ago |
def inbound_ids(self) -> List[int]: |
| 55 |
912788f |
Mardin |
2y ago |
return [i.id for i in self.inbounds] |
| 56 |
912788f |
Mardin |
2y ago |
|
| 57 |
a47eb4c |
Dawsh |
2y ago |
model_config = ConfigDict(from_attributes=True) |