fix: 重命名通知渠道模型避免与 alert 模块冲突
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- NotificationChannel -> TaskNotifyChannel - platform_notification_channels -> platform_task_notify_channels
This commit is contained in:
@@ -6,7 +6,7 @@ from sqlalchemy.orm import Session
|
||||
from sqlalchemy import desc
|
||||
|
||||
from ..database import get_db
|
||||
from ..models.notification_channel import NotificationChannel
|
||||
from ..models.notification_channel import TaskNotifyChannel
|
||||
|
||||
|
||||
router = APIRouter(prefix="/api/notification-channels", tags=["notification-channels"])
|
||||
@@ -42,17 +42,17 @@ async def list_channels(
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""获取通知渠道列表"""
|
||||
query = db.query(NotificationChannel)
|
||||
query = db.query(TaskNotifyChannel)
|
||||
|
||||
if tenant_id:
|
||||
query = query.filter(NotificationChannel.tenant_id == tenant_id)
|
||||
query = query.filter(TaskNotifyChannel.tenant_id == tenant_id)
|
||||
if channel_type:
|
||||
query = query.filter(NotificationChannel.channel_type == channel_type)
|
||||
query = query.filter(TaskNotifyChannel.channel_type == channel_type)
|
||||
if is_enabled is not None:
|
||||
query = query.filter(NotificationChannel.is_enabled == is_enabled)
|
||||
query = query.filter(TaskNotifyChannel.is_enabled == is_enabled)
|
||||
|
||||
total = query.count()
|
||||
items = query.order_by(desc(NotificationChannel.created_at)).offset((page - 1) * size).limit(size).all()
|
||||
items = query.order_by(desc(TaskNotifyChannel.created_at)).offset((page - 1) * size).limit(size).all()
|
||||
|
||||
return {
|
||||
"total": total,
|
||||
@@ -63,7 +63,7 @@ async def list_channels(
|
||||
@router.get("/{channel_id}")
|
||||
async def get_channel(channel_id: int, db: Session = Depends(get_db)):
|
||||
"""获取渠道详情"""
|
||||
channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first()
|
||||
channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first()
|
||||
if not channel:
|
||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||
return format_channel(channel)
|
||||
@@ -72,7 +72,7 @@ async def get_channel(channel_id: int, db: Session = Depends(get_db)):
|
||||
@router.post("")
|
||||
async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)):
|
||||
"""创建通知渠道"""
|
||||
channel = NotificationChannel(
|
||||
channel = TaskNotifyChannel(
|
||||
tenant_id=data.tenant_id,
|
||||
channel_name=data.channel_name,
|
||||
channel_type=data.channel_type,
|
||||
@@ -91,7 +91,7 @@ async def create_channel(data: ChannelCreate, db: Session = Depends(get_db)):
|
||||
@router.put("/{channel_id}")
|
||||
async def update_channel(channel_id: int, data: ChannelUpdate, db: Session = Depends(get_db)):
|
||||
"""更新通知渠道"""
|
||||
channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first()
|
||||
channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first()
|
||||
if not channel:
|
||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||
|
||||
@@ -113,7 +113,7 @@ async def update_channel(channel_id: int, data: ChannelUpdate, db: Session = Dep
|
||||
@router.delete("/{channel_id}")
|
||||
async def delete_channel(channel_id: int, db: Session = Depends(get_db)):
|
||||
"""删除通知渠道"""
|
||||
channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first()
|
||||
channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first()
|
||||
if not channel:
|
||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||
|
||||
@@ -127,7 +127,7 @@ async def test_channel(channel_id: int, db: Session = Depends(get_db)):
|
||||
"""测试通知渠道"""
|
||||
import httpx
|
||||
|
||||
channel = db.query(NotificationChannel).filter(NotificationChannel.id == channel_id).first()
|
||||
channel = db.query(TaskNotifyChannel).filter(TaskNotifyChannel.id == channel_id).first()
|
||||
if not channel:
|
||||
raise HTTPException(status_code=404, detail="渠道不存在")
|
||||
|
||||
@@ -166,7 +166,7 @@ async def test_channel(channel_id: int, db: Session = Depends(get_db)):
|
||||
|
||||
# ==================== Helpers ====================
|
||||
|
||||
def format_channel(channel: NotificationChannel) -> dict:
|
||||
def format_channel(channel: TaskNotifyChannel) -> dict:
|
||||
"""格式化渠道数据"""
|
||||
return {
|
||||
"id": channel.id,
|
||||
|
||||
Reference in New Issue
Block a user