feat: 添加 Profile/Messages API 及 SSE 推送集成
- Profile API: GET/PUT /profile + PUT /profile/password - Messages API: 模型/迁移(005)/服务/路由 + 任务操作自动创建消息 - SSE 推送集成: tasks.py 中 6 个操作触发 SSE 通知 - Alembic 迁移: 004 audit_logs + 005 messages - env.py 导入所有模型确保迁移正确 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
68dac332d4
commit
ea807974cf
@@ -12,6 +12,7 @@ from app.models.ai_config import AIConfig
|
||||
from app.models.review import ReviewTask, Platform
|
||||
from app.models.rule import ForbiddenWord, WhitelistItem, Competitor
|
||||
from app.models.audit_log import AuditLog
|
||||
from app.models.message import Message
|
||||
# 保留 Tenant 兼容旧代码,但新代码应使用 Brand
|
||||
from app.models.tenant import Tenant
|
||||
|
||||
@@ -45,6 +46,8 @@ __all__ = [
|
||||
"Competitor",
|
||||
# 审计日志
|
||||
"AuditLog",
|
||||
# 消息
|
||||
"Message",
|
||||
# 兼容
|
||||
"Tenant",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
消息/通知模型
|
||||
"""
|
||||
from typing import Optional
|
||||
from sqlalchemy import String, Boolean, Text, ForeignKey, Index
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class Message(Base, TimestampMixin):
|
||||
"""消息表"""
|
||||
__tablename__ = "messages"
|
||||
|
||||
id: Mapped[str] = mapped_column(String(64), primary_key=True)
|
||||
|
||||
# 接收者
|
||||
user_id: Mapped[str] = mapped_column(
|
||||
String(64),
|
||||
ForeignKey("users.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
# 消息类型: invite, new_task, pass, reject, appeal, system 等
|
||||
type: Mapped[str] = mapped_column(String(50), nullable=False)
|
||||
|
||||
# 消息内容
|
||||
title: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
content: Mapped[str] = mapped_column(Text, nullable=False)
|
||||
|
||||
# 已读状态
|
||||
is_read: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
||||
|
||||
# 关联信息(可选)
|
||||
related_task_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
related_project_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
sender_name: Mapped[Optional[str]] = mapped_column(String(100), nullable=True)
|
||||
|
||||
__table_args__ = (
|
||||
Index("idx_messages_user_id", "user_id"),
|
||||
Index("idx_messages_user_read", "user_id", "is_read"),
|
||||
)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Message(id={self.id}, user_id={self.user_id}, type={self.type})>"
|
||||
Reference in New Issue
Block a user