Files
wecom_it_smart_desk/backend/app/schemas/knowledge_base.py
T

64 lines
2.4 KiB
Python

# =============================================================================
# 企微IT智能服务台 — 知识库 Pydantic Schema
# =============================================================================
# 说明:定义知识库FAQ的请求/响应数据结构
# 支持 CRUD 操作:创建、读取、更新、删除
# =============================================================================
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel, Field
# --------------------------------------------------------------------------
# 创建知识库条目 Schema
# --------------------------------------------------------------------------
class KnowledgeBaseCreate(BaseModel):
"""创建知识库条目请求 Schema。"""
category: str = Field(default="其他", max_length=64, description="分类")
title: str = Field(..., min_length=1, max_length=256, description="问题标题")
content: str = Field(..., min_length=1, description="答案内容")
tags: List[str] = Field(default_factory=list, description="标签列表")
# --------------------------------------------------------------------------
# 更新知识库条目 Schema
# --------------------------------------------------------------------------
class KnowledgeBaseUpdate(BaseModel):
"""更新知识库条目请求 Schema。"""
category: Optional[str] = Field(None, max_length=64, description="分类")
title: Optional[str] = Field(None, max_length=256, description="问题标题")
content: Optional[str] = Field(None, description="答案内容")
tags: Optional[List[str]] = Field(None, description="标签列表")
# --------------------------------------------------------------------------
# 知识库条目响应 Schema
# --------------------------------------------------------------------------
class KnowledgeBaseResponse(BaseModel):
"""知识库条目响应 Schema。"""
id: str
category: str
title: str
content: str
tags: List[str]
view_count: int = 0
use_count: int = 0
created_at: datetime
updated_at: datetime
model_config = {"from_attributes": True}
# --------------------------------------------------------------------------
# 知识库列表响应 Schema
# --------------------------------------------------------------------------
class KnowledgeBaseListResponse(BaseModel):
"""知识库列表响应 Schema。"""
items: List[KnowledgeBaseResponse]