97 lines
2.3 KiB
Python
97 lines
2.3 KiB
Python
"""Alert schemas for request/response validation."""
|
||
import uuid
|
||
from datetime import datetime
|
||
from typing import Optional
|
||
|
||
from pydantic import BaseModel, Field
|
||
|
||
|
||
# ============================================================
|
||
# Alert Schemas
|
||
# ============================================================
|
||
|
||
class AlertResponse(BaseModel):
|
||
"""告警响应"""
|
||
id: uuid.UUID
|
||
brand_id: uuid.UUID
|
||
user_id: uuid.UUID
|
||
alert_type: str
|
||
severity: str
|
||
title: str
|
||
message: str
|
||
data: Optional[dict] = None
|
||
is_read: bool
|
||
created_at: datetime
|
||
|
||
model_config = {"from_attributes": True}
|
||
|
||
|
||
class AlertListResponse(BaseModel):
|
||
"""告警列表响应"""
|
||
items: list[AlertResponse]
|
||
total: int
|
||
|
||
|
||
class AlertUnreadCountResponse(BaseModel):
|
||
"""未读告警数量响应"""
|
||
unread_count: int
|
||
|
||
|
||
class AlertReadResponse(BaseModel):
|
||
"""标记已读响应"""
|
||
id: uuid.UUID
|
||
is_read: bool
|
||
|
||
model_config = {"from_attributes": True}
|
||
|
||
|
||
class AlertReadAllResponse(BaseModel):
|
||
"""全部标记已读响应"""
|
||
updated_count: int
|
||
|
||
|
||
# ============================================================
|
||
# AlertSetting Schemas
|
||
# ============================================================
|
||
|
||
class AlertSettingResponse(BaseModel):
|
||
"""告警设置响应"""
|
||
id: uuid.UUID
|
||
brand_id: uuid.UUID
|
||
user_id: uuid.UUID
|
||
alert_type: str
|
||
enabled: bool
|
||
threshold: Optional[float] = None
|
||
created_at: datetime
|
||
updated_at: datetime
|
||
|
||
model_config = {"from_attributes": True}
|
||
|
||
|
||
class AlertSettingUpdate(BaseModel):
|
||
"""告警设置更新"""
|
||
enabled: Optional[bool] = None
|
||
threshold: Optional[float] = Field(None, ge=0, le=100, description="阈值(0-100)")
|
||
|
||
|
||
class AlertSettingCreate(BaseModel):
|
||
"""告警设置创建"""
|
||
brand_id: uuid.UUID
|
||
alert_type: str = Field(
|
||
...,
|
||
pattern=r"^(score_drop|score_rise|negative_sentiment|competitor_overtake|new_platform_mention)$",
|
||
)
|
||
enabled: bool = True
|
||
threshold: Optional[float] = Field(None, ge=0, le=100, description="阈值(0-100)")
|
||
|
||
|
||
class AlertSettingListResponse(BaseModel):
|
||
"""告警设置列表响应"""
|
||
items: list[AlertSettingResponse]
|
||
total: int
|
||
|
||
|
||
class AlertSettingBulkUpdate(BaseModel):
|
||
"""批量更新告警设置"""
|
||
settings: list[AlertSettingCreate]
|