mirror of
https://git.oceanpay.cc/danial/kami_apple_exchage.git
synced 2025-12-18 22:29:09 +00:00
- 新增 CODEBUDDY.md、GEMINI.md、GEMINI_CN.md 等项目文档 - 更新 Dockerfile 和其他配置文件 - 优化部分代码结构,如 orders.py、tasks.py 等 - 新增 .dockerignore 文件
77 lines
1.9 KiB
Python
77 lines
1.9 KiB
Python
"""
|
|
链接相关的Pydantic模型
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
|
|
class LinkBase(BaseModel):
|
|
"""链接基础模型"""
|
|
|
|
url: str = Field(..., description="链接URL", max_length=255)
|
|
amount: float = Field(..., description="金额", gt=0)
|
|
|
|
|
|
class LinkCreate(LinkBase):
|
|
"""创建链接请求模型"""
|
|
|
|
pass
|
|
|
|
|
|
class LinkUpdate(BaseModel):
|
|
"""更新链接请求模型"""
|
|
|
|
url: str | None = Field(None, description="链接URL", max_length=255)
|
|
amount: float | None = Field(None, description="金额", gt=0)
|
|
|
|
|
|
class LinkResponse(LinkBase):
|
|
"""链接响应模型"""
|
|
|
|
id: str = Field(..., description="链接ID")
|
|
created_at: str = Field(..., description="创建时间")
|
|
updated_at: str = Field(..., description="更新时间")
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
@classmethod
|
|
def from_orm(cls, obj):
|
|
"""Custom ORM conversion to handle datetime serialization"""
|
|
data = {}
|
|
for field in cls.model_fields:
|
|
value = getattr(obj, field, None)
|
|
if isinstance(value, datetime):
|
|
data[field] = value.isoformat()
|
|
else:
|
|
data[field] = value
|
|
|
|
return cls(**data)
|
|
|
|
|
|
class LinkListResponse(BaseModel):
|
|
"""链接列表响应模型"""
|
|
|
|
items: list[LinkResponse]
|
|
total: int
|
|
page: int
|
|
size: int
|
|
pages: int
|
|
|
|
|
|
class LinkPoolResponse(BaseModel):
|
|
"""轮询池响应模型"""
|
|
|
|
link: LinkResponse
|
|
pool_position: int = Field(..., description="在轮询池中的位置")
|
|
|
|
|
|
class LinkStatsResponse(BaseModel):
|
|
"""链接统计响应模型"""
|
|
|
|
total_links: int = Field(..., description="总链接数")
|
|
total_orders: int = Field(..., description="总订单数")
|
|
average_amount: float = Field(..., description="平均金额")
|
|
min_amount: float = Field(..., description="最小金额")
|
|
max_amount: float = Field(..., description="最大金额")
|