nex_docus/backend/app/schemas/project.py

114 lines
3.5 KiB
Python
Raw Normal View History

2025-12-20 11:18:59 +00:00
"""
项目相关的 Pydantic Schema
"""
2025-12-29 12:53:50 +00:00
from pydantic import BaseModel, Field, field_validator
2025-12-20 11:18:59 +00:00
from typing import Optional
from datetime import datetime
class ProjectBase(BaseModel):
"""项目基础 Schema"""
name: str = Field(..., min_length=1, max_length=100, description="项目名称")
description: Optional[str] = Field(None, max_length=500, description="项目描述")
is_public: int = Field(0, description="是否公开0-私有 1-公开")
class ProjectCreate(ProjectBase):
"""创建项目 Schema"""
pass
class ProjectUpdate(BaseModel):
"""更新项目 Schema"""
name: Optional[str] = Field(None, min_length=1, max_length=100)
description: Optional[str] = None
is_public: Optional[int] = None
2026-05-09 02:45:30 +00:00
public_access_pass: Optional[str] = Field(None, max_length=100)
2025-12-20 11:18:59 +00:00
cover_image: Optional[str] = None
status: Optional[int] = None
class ProjectResponse(ProjectBase):
"""项目响应 Schema"""
id: int
storage_key: str
owner_id: int
is_template: int
status: int
cover_image: Optional[str] = None
visit_count: int
created_at: datetime
updated_at: datetime
class Config:
from_attributes = True
class ProjectMemberAdd(BaseModel):
"""添加项目成员 Schema"""
user_id: int = Field(..., description="用户ID")
2025-12-29 12:53:50 +00:00
role: str = Field("viewer", description="项目角色: admin/editor/viewer")
@field_validator('role')
@classmethod
def validate_role(cls, v):
if v not in ['admin', 'editor', 'viewer']:
raise ValueError('role must be one of: admin, editor, viewer')
return v
2025-12-20 11:18:59 +00:00
class ProjectMemberUpdate(BaseModel):
"""更新项目成员 Schema"""
2025-12-29 12:53:50 +00:00
role: str = Field(..., description="项目角色: admin/editor/viewer")
@field_validator('role')
@classmethod
def validate_role(cls, v):
if v not in ['admin', 'editor', 'viewer']:
raise ValueError('role must be one of: admin, editor, viewer')
return v
2025-12-20 11:18:59 +00:00
class ProjectMemberResponse(BaseModel):
"""项目成员响应 Schema"""
id: int
project_id: int
user_id: int
2025-12-29 12:53:50 +00:00
role: str
2025-12-20 11:18:59 +00:00
joined_at: datetime
class Config:
from_attributes = True
2026-05-09 02:45:30 +00:00
class ProjectShareInfo(BaseModel):
"""项目公开分享信息响应 Schema"""
enabled: bool = Field(..., description="是否已开启项目公开")
share_url: Optional[str] = Field(None, description="项目分享链接")
has_password: bool = Field(..., description="是否设置了访问密码")
access_pass: Optional[str] = Field(None, description="访问密码(仅项目所有者可见)")
2025-12-20 11:18:59 +00:00
class ProjectShareSettings(BaseModel):
"""项目分享设置 Schema"""
2026-05-09 02:45:30 +00:00
access_pass: Optional[str] = Field(None, max_length=100, description="访问密码None 表示取消密码)")
2025-12-20 11:18:59 +00:00
2026-05-09 02:45:30 +00:00
class FileShareCreate(BaseModel):
"""文件分享创建/更新 Schema"""
file_path: str = Field(..., min_length=1, description="文件路径")
access_pass: Optional[str] = Field(None, max_length=100, description="访问密码")
class FileShareInfo(BaseModel):
"""文件分享信息响应 Schema"""
file_path: str = Field(..., description="文件路径")
share_url: str = Field(..., description="文件分享链接")
2025-12-20 11:18:59 +00:00
has_password: bool = Field(..., description="是否设置了访问密码")
access_pass: Optional[str] = Field(None, description="访问密码(仅项目所有者可见)")
2026-02-09 10:08:38 +00:00
class ProjectTransfer(BaseModel):
"""转移项目所有权 Schema"""
2026-05-09 02:45:30 +00:00
new_owner_id: int = Field(..., description="新所有者ID")