refactor(api): Align user schemas with CLI output and new features

This commit is contained in:
Whispering Wind
2025-08-12 23:37:11 +03:30
committed by GitHub
parent 75033231f2
commit 644c43b504

View File

@ -1,23 +1,20 @@
from typing import Optional, List from typing import Optional, List
from pydantic import BaseModel, RootModel from pydantic import BaseModel, RootModel, Field
# WE CAN'T USE SHARED SCHEMA BECAUSE THE CLI IS RETURNING SAME FIELD IN DIFFERENT NAMES SOMETIMES
# WHAT I'M SAYING IS THAT OUR CODE IN HERE WILL BE SPAGHETTI CODE IF WE WANT TO HAVE CONSISTENCY IN ALL RESPONSES OF THE APIs
# THE MAIN PROBLEM IS IN THE CLI CODE NOT IN THE WEB PANEL CODE (HERE)
class UserInfoResponse(BaseModel): class UserInfoResponse(BaseModel):
password: str password: str
max_download_bytes: int max_download_bytes: int
expiration_days: int expiration_days: int
account_creation_date: str account_creation_date: str
blocked: bool blocked: bool
status: str | None = None unlimited_ip: bool = Field(False, alias='unlimited_user')
upload_bytes: int | None = None status: Optional[str] = None
download_bytes: int | None = None upload_bytes: Optional[int] = None
download_bytes: Optional[int] = None
class UserListResponse(RootModel): # type: ignore class UserListResponse(RootModel):
root: dict[str, UserInfoResponse] root: dict[str, UserInfoResponse]
@ -25,18 +22,19 @@ class AddUserInputBody(BaseModel):
username: str username: str
traffic_limit: int traffic_limit: int
expiration_days: int expiration_days: int
password: str | None = None password: Optional[str] = None
creation_date: str | None = None creation_date: Optional[str] = None
unlimited: bool = False
class EditUserInputBody(BaseModel): class EditUserInputBody(BaseModel):
# username: str new_username: Optional[str] = None
new_username: str | None = None new_traffic_limit: Optional[int] = None
new_traffic_limit: int | None = None new_expiration_days: Optional[int] = None
new_expiration_days: int | None = None
renew_password: bool = False renew_password: bool = False
renew_creation_date: bool = False renew_creation_date: bool = False
blocked: bool = False blocked: Optional[bool] = None
unlimited_ip: Optional[bool] = None
class NodeUri(BaseModel): class NodeUri(BaseModel):
name: str name: str