feat(api): integrate user note field into api endpoints

This commit is contained in:
ReturnFI
2025-10-28 16:36:11 +00:00
parent dce23100a1
commit 413442ba5d
2 changed files with 5 additions and 2 deletions

View File

@ -11,6 +11,7 @@ class UserInfoResponse(BaseModel):
account_creation_date: Optional[str] = None account_creation_date: Optional[str] = None
blocked: bool blocked: bool
unlimited_ip: bool = Field(False, alias='unlimited_user') unlimited_ip: bool = Field(False, alias='unlimited_user')
note: Optional[str] = None
status: Optional[str] = None status: Optional[str] = None
upload_bytes: Optional[int] = None upload_bytes: Optional[int] = None
download_bytes: Optional[int] = None download_bytes: Optional[int] = None
@ -30,6 +31,7 @@ class AddUserInputBody(BaseModel):
password: Optional[str] = None password: Optional[str] = None
creation_date: Optional[str] = None creation_date: Optional[str] = None
unlimited: bool = False unlimited: bool = False
note: Optional[str] = None
@field_validator('username') @field_validator('username')
def validate_username(cls, v): def validate_username(cls, v):
@ -61,6 +63,7 @@ class EditUserInputBody(BaseModel):
renew_creation_date: bool = False renew_creation_date: bool = False
blocked: Optional[bool] = None blocked: Optional[bool] = None
unlimited_ip: Optional[bool] = None unlimited_ip: Optional[bool] = None
note: Optional[str] = None
@field_validator('new_username') @field_validator('new_username')
def validate_new_username(cls, v): def validate_new_username(cls, v):

View File

@ -47,7 +47,7 @@ async def add_user_api(body: AddUserInputBody):
detail=f"{str(e)}") detail=f"{str(e)}")
try: try:
cli_api.add_user(body.username, body.traffic_limit, body.expiration_days, body.password, body.creation_date, body.unlimited) cli_api.add_user(body.username, body.traffic_limit, body.expiration_days, body.password, body.creation_date, body.unlimited, body.note)
return DetailResponse(detail=f'User {body.username} has been added.') return DetailResponse(detail=f'User {body.username} has been added.')
except cli_api.CommandExecutionError as e: except cli_api.CommandExecutionError as e:
if "User already exists" in str(e): if "User already exists" in str(e):
@ -172,7 +172,7 @@ async def edit_user_api(username: str, body: EditUserInputBody):
cli_api.kick_users_by_name([username]) cli_api.kick_users_by_name([username])
cli_api.traffic_status(display_output=False) cli_api.traffic_status(display_output=False)
cli_api.edit_user(username, body.new_username, body.new_traffic_limit, body.new_expiration_days, cli_api.edit_user(username, body.new_username, body.new_traffic_limit, body.new_expiration_days,
body.renew_password, body.renew_creation_date, body.blocked, body.unlimited_ip) body.renew_password, body.renew_creation_date, body.blocked, body.unlimited_ip, body.note)
return DetailResponse(detail=f'User {username} has been edited.') return DetailResponse(detail=f'User {username} has been edited.')
except Exception as e: except Exception as e:
raise HTTPException(status_code=400, detail=f'Error: {str(e)}') raise HTTPException(status_code=400, detail=f'Error: {str(e)}')