93 lines
2.6 KiB
Python
93 lines
2.6 KiB
Python
"""
|
||
项目相关的 Pydantic Schema
|
||
"""
|
||
from pydantic import BaseModel, Field, field_validator
|
||
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
|
||
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")
|
||
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
|
||
|
||
|
||
class ProjectMemberUpdate(BaseModel):
|
||
"""更新项目成员 Schema"""
|
||
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
|
||
|
||
|
||
class ProjectMemberResponse(BaseModel):
|
||
"""项目成员响应 Schema"""
|
||
id: int
|
||
project_id: int
|
||
user_id: int
|
||
role: str
|
||
joined_at: datetime
|
||
|
||
class Config:
|
||
from_attributes = True
|
||
|
||
|
||
class ProjectShareSettings(BaseModel):
|
||
"""项目分享设置 Schema"""
|
||
access_pass: Optional[str] = Field(None, max_length=100, description="访问密码(None表示取消密码)")
|
||
|
||
|
||
class ProjectShareInfo(BaseModel):
|
||
"""项目分享信息响应 Schema"""
|
||
share_url: str = Field(..., description="分享链接")
|
||
has_password: bool = Field(..., description="是否设置了访问密码")
|
||
access_pass: Optional[str] = Field(None, description="访问密码(仅项目所有者可见)")
|