Newer
Older
safe-algo-pro / apis / push_config.py
zhangyingjie on 7 Nov 1 KB 增加数据推送功能
from typing import List

from fastapi import APIRouter, Depends
from sqlmodel import Session

from apis.base import standard_response, StandardResponse
from db.database import get_db
from entity.push_config import PushConfig, PushConfigCreate
from services.push_config_service import PushConfigService

router = APIRouter()


@router.get("/list", response_model=StandardResponse[List[PushConfig]])
def get_push_config_list(db: Session = Depends(get_db)):
    service = PushConfigService(db)
    push_configs = service.get_push_config_list()
    return standard_response(data=push_configs)


@router.get("/get_by_type", response_model=StandardResponse[PushConfig])
def get_by_type(push_type: int, db: Session = Depends(get_db)):
    service = PushConfigService(db)
    push_config = service.get_push_config(push_type)
    return standard_response(data=push_config)


@router.post("/set_push_config", response_model=StandardResponse[PushConfig])
def set_push_config(push_config: PushConfigCreate, db: Session = Depends(get_db)):
    service = PushConfigService(db)
    push_config = service.set_push_config(push_config)
    return standard_response(data=push_config)