From df30b71077bcaffecf6d79df6bc414f95b499bea Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 13 Jul 2023 20:46:31 +0800 Subject: [PATCH] fix --- app/api/endpoints/message.py | 8 ++++---- app/schemas/context.py | 20 ++++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/api/endpoints/message.py b/app/api/endpoints/message.py index 94647419..5613212d 100644 --- a/app/api/endpoints/message.py +++ b/app/api/endpoints/message.py @@ -13,7 +13,7 @@ from app.db import get_db from app.db.systemconfig_oper import SystemConfigOper from app.log import logger from app.modules.wechat.WXBizMsgCrypt3 import WXBizMsgCrypt -from app.schemas import Notification +from app.schemas import NotificationSwitch from app.schemas.types import SystemConfigKey, NotificationType router = APIRouter() @@ -62,7 +62,7 @@ def wechat_verify(echostr: str, msg_signature: str, return PlainTextResponse(sEchoStr) -@router.get("/switchs", summary="查询通知消息渠道开关", response_model=List[Notification]) +@router.get("/switchs", summary="查询通知消息渠道开关", response_model=List[NotificationSwitch]) def read_switchs(db: Session = Depends(get_db), _: schemas.TokenPayload = Depends(verify_token)) -> Any: """ @@ -73,13 +73,13 @@ def read_switchs(db: Session = Depends(get_db), switchs = SystemConfigOper(db).get(SystemConfigKey.NotificationChannels) if not switchs: for noti in NotificationType: - return_list.append(Notification(mtype=noti.value, switch=True)) + return_list.append(NotificationSwitch(mtype=noti.value, wechat=True, telegram=True, slack=True)) return return_list @router.put("/switchs", summary="设置通知消息渠道开关", response_model=schemas.Response) -def set_switchs(switchs: List[Notification], +def set_switchs(switchs: List[NotificationSwitch], db: Session = Depends(get_db), _: schemas.TokenPayload = Depends(verify_token)) -> Any: """ diff --git a/app/schemas/context.py b/app/schemas/context.py index ed7b5e7b..a03e1a2c 100644 --- a/app/schemas/context.py +++ b/app/schemas/context.py @@ -3,7 +3,7 @@ from typing import Optional, Dict, List, Union from pydantic import BaseModel -from app.schemas.types import MediaType +from app.schemas.types import MediaType, NotificationType class MetaInfo(BaseModel): @@ -314,7 +314,7 @@ class Notification(BaseModel): 消息 """ # 消息类型 - mtype: Optional[str] = None + mtype: Optional[NotificationType] = None # 标题 title: Optional[str] = None # 内容 @@ -325,5 +325,17 @@ class Notification(BaseModel): link: Optional[str] = None # 用户ID user_id: Optional[str] = None - # 开关 - switch: Optional[bool] = True + + +class NotificationSwitch(BaseModel): + """ + 消息开关 + """ + # 消息类型 + mtype: Optional[str] = None + # 微信开关 + wechat: Optional[bool] = False + # TG开关 + telegram: Optional[bool] = False + # Slack开关 + slack: Optional[bool] = False