更新查询方式
This commit is contained in:
@@ -67,7 +67,7 @@ from .object import (
|
||||
)
|
||||
from .physical_file import PhysicalFile, PhysicalFileBase
|
||||
from .order import Order, OrderStatus, OrderType
|
||||
from .policy import Policy, PolicyBase, PolicyOptions, PolicyOptionsBase, PolicyType
|
||||
from .policy import Policy, PolicyBase, PolicyOptions, PolicyOptionsBase, PolicyType, PolicySummary
|
||||
from .redeem import Redeem, RedeemType
|
||||
from .report import Report, ReportReason
|
||||
from .setting import (
|
||||
@@ -75,11 +75,11 @@ from .setting import (
|
||||
# 管理员DTO
|
||||
SettingItem, SettingsListResponse, SettingsUpdateRequest, SettingsUpdateResponse,
|
||||
)
|
||||
from .share import Share, ShareBase, ShareCreateRequest, ShareResponse
|
||||
from .share import Share, ShareBase, ShareCreateRequest, ShareResponse, AdminShareListItem
|
||||
from .source_link import SourceLink
|
||||
from .storage_pack import StoragePack
|
||||
from .tag import Tag, TagType
|
||||
from .task import Task, TaskProps, TaskPropsBase, TaskStatus, TaskType
|
||||
from .task import Task, TaskProps, TaskPropsBase, TaskStatus, TaskType, TaskSummary
|
||||
from .webdav import WebDAV
|
||||
|
||||
from .database import engine, get_session
|
||||
@@ -96,4 +96,7 @@ from .model_base import (
|
||||
VersionInfo,
|
||||
AdminSummaryData,
|
||||
AdminSummaryResponse,
|
||||
)
|
||||
)
|
||||
|
||||
# mixin 中的通用分页模型
|
||||
from .mixin import ListResponse
|
||||
@@ -124,8 +124,8 @@ class GroupUpdateRequest(SQLModelBase):
|
||||
"""关联的存储策略UUID列表"""
|
||||
|
||||
|
||||
class GroupDetailResponse(GroupAllOptionsBase):
|
||||
"""用户组详情响应 DTO"""
|
||||
class GroupCoreBase(SQLModelBase):
|
||||
"""用户组核心字段(从 Group 模型提取)"""
|
||||
|
||||
id: UUID
|
||||
"""用户组UUID"""
|
||||
@@ -148,12 +148,35 @@ class GroupDetailResponse(GroupAllOptionsBase):
|
||||
speed_limit: int = 0
|
||||
"""速度限制 (KB/s)"""
|
||||
|
||||
|
||||
class GroupDetailResponse(GroupCoreBase, GroupAllOptionsBase):
|
||||
"""用户组详情响应 DTO"""
|
||||
|
||||
user_count: int = 0
|
||||
"""用户数量"""
|
||||
|
||||
policy_ids: list[UUID] = []
|
||||
"""关联的存储策略UUID列表"""
|
||||
|
||||
@classmethod
|
||||
def from_group(
|
||||
cls,
|
||||
group: "Group",
|
||||
user_count: int,
|
||||
policies: list["Policy"],
|
||||
) -> "GroupDetailResponse":
|
||||
"""从 Group ORM 对象构建"""
|
||||
opts = group.options
|
||||
return cls(
|
||||
# GroupCoreBase 字段(从 Group 模型提取)
|
||||
**GroupCoreBase.model_validate(group, from_attributes=True).model_dump(),
|
||||
# GroupAllOptionsBase 字段(从 GroupOptions 提取)
|
||||
**(GroupAllOptionsBase.model_validate(opts, from_attributes=True).model_dump() if opts else {}),
|
||||
# 计算字段
|
||||
user_count=user_count,
|
||||
policy_ids=[p.id for p in policies],
|
||||
)
|
||||
|
||||
|
||||
class GroupListResponse(SQLModelBase):
|
||||
"""用户组列表响应 DTO"""
|
||||
|
||||
@@ -695,6 +695,32 @@ class AdminFileResponse(ObjectResponse):
|
||||
ban_reason: str | None = None
|
||||
"""封禁原因"""
|
||||
|
||||
@classmethod
|
||||
def from_object(
|
||||
cls,
|
||||
obj: "Object",
|
||||
owner: "User | None",
|
||||
policy: "Policy | None",
|
||||
) -> "AdminFileResponse":
|
||||
"""从 Object ORM 对象构建"""
|
||||
return cls(
|
||||
# ObjectBase 字段
|
||||
**ObjectBase.model_validate(obj, from_attributes=True).model_dump(),
|
||||
# ObjectResponse 字段
|
||||
id=obj.id,
|
||||
thumb=False,
|
||||
date=obj.updated_at,
|
||||
create_date=obj.created_at,
|
||||
source_enabled=False,
|
||||
# AdminFileResponse 字段
|
||||
owner_id=obj.owner_id,
|
||||
owner_username=owner.username if owner else "unknown",
|
||||
policy_name=policy.name if policy else "unknown",
|
||||
is_banned=obj.is_banned,
|
||||
banned_at=obj.banned_at,
|
||||
ban_reason=obj.ban_reason,
|
||||
)
|
||||
|
||||
|
||||
class FileBanRequest(SQLModelBase):
|
||||
"""文件封禁请求 DTO"""
|
||||
|
||||
@@ -78,6 +78,34 @@ class PolicyBase(SQLModelBase):
|
||||
"""是否开启源链接访问"""
|
||||
|
||||
|
||||
# ==================== DTO 模型 ====================
|
||||
|
||||
|
||||
class PolicySummary(SQLModelBase):
|
||||
"""策略摘要,用于列表展示"""
|
||||
|
||||
id: UUID
|
||||
"""策略UUID"""
|
||||
|
||||
name: str
|
||||
"""策略名称"""
|
||||
|
||||
type: PolicyType
|
||||
"""策略类型"""
|
||||
|
||||
server: str | None
|
||||
"""服务器地址"""
|
||||
|
||||
max_size: int
|
||||
"""最大文件尺寸"""
|
||||
|
||||
is_private: bool
|
||||
"""是否私有"""
|
||||
|
||||
|
||||
# ==================== 数据库模型 ====================
|
||||
|
||||
|
||||
class PolicyOptionsBase(SQLModelBase):
|
||||
"""存储策略选项的基础模型"""
|
||||
|
||||
|
||||
@@ -160,3 +160,61 @@ class ShareResponse(SQLModelBase):
|
||||
|
||||
has_password: bool
|
||||
"""是否有密码"""
|
||||
|
||||
|
||||
class ShareListItemBase(SQLModelBase):
|
||||
"""分享列表项基础字段"""
|
||||
|
||||
id: int
|
||||
"""分享ID"""
|
||||
|
||||
code: str
|
||||
"""分享码"""
|
||||
|
||||
views: int
|
||||
"""浏览次数"""
|
||||
|
||||
downloads: int
|
||||
"""下载次数"""
|
||||
|
||||
remain_downloads: int | None
|
||||
"""剩余下载次数"""
|
||||
|
||||
expires: datetime | None
|
||||
"""过期时间"""
|
||||
|
||||
preview_enabled: bool
|
||||
"""是否允许预览"""
|
||||
|
||||
score: int
|
||||
"""积分"""
|
||||
|
||||
user_id: UUID
|
||||
"""用户UUID"""
|
||||
|
||||
created_at: datetime
|
||||
"""创建时间"""
|
||||
|
||||
|
||||
class AdminShareListItem(ShareListItemBase):
|
||||
"""管理员分享列表项 DTO,添加关联字段"""
|
||||
|
||||
username: str | None
|
||||
"""用户名"""
|
||||
|
||||
object_name: str | None
|
||||
"""对象名称"""
|
||||
|
||||
@classmethod
|
||||
def from_share(
|
||||
cls,
|
||||
share: "Share",
|
||||
user: "User | None",
|
||||
obj: "Object | None",
|
||||
) -> "AdminShareListItem":
|
||||
"""从 Share ORM 对象构建"""
|
||||
return cls(
|
||||
**ShareListItemBase.model_validate(share, from_attributes=True).model_dump(),
|
||||
username=user.username if user else None,
|
||||
object_name=obj.name if obj else None,
|
||||
)
|
||||
|
||||
@@ -9,8 +9,8 @@ from .base import SQLModelBase
|
||||
from .mixin import TableBaseMixin
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .user import User
|
||||
from .download import Download
|
||||
from .user import User
|
||||
|
||||
|
||||
class TaskStatus(StrEnum):
|
||||
@@ -31,6 +31,55 @@ class TaskType(StrEnum):
|
||||
pass
|
||||
|
||||
|
||||
# ==================== DTO 模型 ====================
|
||||
|
||||
|
||||
class TaskSummaryBase(SQLModelBase):
|
||||
"""任务摘要基础字段"""
|
||||
|
||||
id: int
|
||||
"""任务ID"""
|
||||
|
||||
type: int
|
||||
"""任务类型"""
|
||||
|
||||
status: TaskStatus
|
||||
"""任务状态"""
|
||||
|
||||
progress: int
|
||||
"""进度(0-100)"""
|
||||
|
||||
error: str | None
|
||||
"""错误信息"""
|
||||
|
||||
user_id: UUID
|
||||
"""用户UUID"""
|
||||
|
||||
created_at: datetime
|
||||
"""创建时间"""
|
||||
|
||||
updated_at: datetime
|
||||
"""更新时间"""
|
||||
|
||||
|
||||
class TaskSummary(TaskSummaryBase):
|
||||
"""任务摘要,用于管理员列表展示"""
|
||||
|
||||
username: str | None
|
||||
"""用户名"""
|
||||
|
||||
@classmethod
|
||||
def from_task(cls, task: "Task", user: "User | None") -> "TaskSummary":
|
||||
"""从 Task ORM 对象构建"""
|
||||
return cls(
|
||||
**TaskSummaryBase.model_validate(task, from_attributes=True).model_dump(),
|
||||
username=user.username if user else None,
|
||||
)
|
||||
|
||||
|
||||
# ==================== 数据库模型 ====================
|
||||
|
||||
|
||||
class TaskPropsBase(SQLModelBase):
|
||||
"""任务属性基础模型"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user