初始化
This commit is contained in:
BIN
schema/__pycache__/device_schema.cpython-312.pyc
Normal file
BIN
schema/__pycache__/device_schema.cpython-312.pyc
Normal file
Binary file not shown.
BIN
schema/__pycache__/response_schema.cpython-312.pyc
Normal file
BIN
schema/__pycache__/response_schema.cpython-312.pyc
Normal file
Binary file not shown.
BIN
schema/__pycache__/user_schema.cpython-312.pyc
Normal file
BIN
schema/__pycache__/user_schema.cpython-312.pyc
Normal file
Binary file not shown.
51
schema/device_schema.py
Normal file
51
schema/device_schema.py
Normal file
@ -0,0 +1,51 @@
|
||||
import hashlib
|
||||
from datetime import datetime
|
||||
from typing import Optional, List, Dict
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# 请求模型(前端传参校验)
|
||||
# ------------------------------
|
||||
class DeviceCreateRequest(BaseModel):
|
||||
"""设备流信息创建请求模型"""
|
||||
ip: Optional[str] = Field(..., max_length=100, description="设备IP地址")
|
||||
hostname: Optional[str] = Field(None, max_length=100, description="设备别名")
|
||||
params: Optional[Dict] = Field(None, description="设备详细信息")
|
||||
|
||||
|
||||
def md5_encrypt(text: str) -> str:
|
||||
"""对字符串进行MD5加密"""
|
||||
if not text:
|
||||
return ""
|
||||
md5_hash = hashlib.md5()
|
||||
md5_hash.update(text.encode('utf-8'))
|
||||
return md5_hash.hexdigest()
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# 响应模型(后端返回设备数据)
|
||||
# ------------------------------
|
||||
class DeviceResponse(BaseModel):
|
||||
"""设备流信息响应模型(字段与表结构完全对齐)"""
|
||||
id: int = Field(..., description="设备ID")
|
||||
hostname: Optional[str] = Field(None, max_length=100, description="设备别名")
|
||||
rtmp_push_url: Optional[str] = Field(None, description="需要推送的RTMP地址")
|
||||
live_webrtc_url: Optional[str] = Field(None, description="直播的Webrtc地址")
|
||||
detection_webrtc_url: Optional[str] = Field(None, description="检测的Webrtc地址")
|
||||
device_online_status: int = Field(..., description="设备在线状态(1-在线、0-离线)")
|
||||
device_type: Optional[str] = Field(None, description="设备类型")
|
||||
alarm_count: int = Field(..., description="报警次数")
|
||||
params: Optional[str] = Field(None, description="设备详细信息")
|
||||
created_at: datetime = Field(..., description="记录创建时间")
|
||||
updated_at: datetime = Field(..., description="记录更新时间")
|
||||
|
||||
# 支持从数据库查询结果转换
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class DeviceListResponse(BaseModel):
|
||||
"""设备流信息列表响应模型"""
|
||||
total: int = Field(..., description="设备总数")
|
||||
devices: List[DeviceResponse] = Field(..., description="设备列表")
|
13
schema/response_schema.py
Normal file
13
schema/response_schema.py
Normal file
@ -0,0 +1,13 @@
|
||||
from typing import Optional, Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class APIResponse(BaseModel):
|
||||
"""统一 API 响应模型(所有接口必返此格式)"""
|
||||
code: int = Field(..., description="状态码:200=成功、4xx=客户端错误、5xx=服务端错误")
|
||||
message: str = Field(..., description="响应信息:成功/错误描述")
|
||||
data: Optional[Any] = Field(None, description="响应数据:成功时返回、错误时为 None")
|
||||
|
||||
# Pydantic V2 配置(支持从 ORM 对象转换)
|
||||
model_config = {"from_attributes": True}
|
32
schema/user_schema.py
Normal file
32
schema/user_schema.py
Normal file
@ -0,0 +1,32 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# 请求模型(前端传参校验)
|
||||
# ------------------------------
|
||||
class UserRegisterRequest(BaseModel):
|
||||
"""用户注册请求模型"""
|
||||
username: str = Field(..., min_length=3, max_length=50, description="用户名(3-50字符)")
|
||||
password: str = Field(..., min_length=6, max_length=100, description="密码(6-100字符)")
|
||||
|
||||
|
||||
class UserLoginRequest(BaseModel):
|
||||
"""用户登录请求模型"""
|
||||
username: str = Field(..., description="用户名")
|
||||
password: str = Field(..., description="密码")
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# 响应模型(后端返回用户数据)
|
||||
# ------------------------------
|
||||
class UserResponse(BaseModel):
|
||||
"""用户信息响应模型(隐藏密码等敏感字段)"""
|
||||
id: int = Field(..., description="用户ID")
|
||||
username: str = Field(..., description="用户名")
|
||||
created_at: datetime = Field(..., description="创建时间")
|
||||
updated_at: datetime = Field(..., description="更新时间")
|
||||
|
||||
# Pydantic V2 配置(支持从数据库查询结果转换)
|
||||
model_config = {"from_attributes": True}
|
Reference in New Issue
Block a user