from fastapi import Depends from sqlalchemy.orm import Session from fastapi import APIRouter from app.common.security.auth import verify_users from constants.constants import CONSTANTS from utils import * import app.crud as crud from app import get_db, schemas router = APIRouter( prefix="/jpt/constants", tags=["constants-常量管理"], ) def format_constants(constants: dict): return [{'id': k, 'value': v} for k, v in constants.items()] @router.get("/datasources") @web_try() @sxtimeit def get_datasources(token_data: schemas.TokenData = Depends(verify_users)): return format_constants(CONSTANTS['DATASOURCES']) @router.get("/") @web_try() @sxtimeit def get_constants(type: str,token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): return crud.get_constant_list(db, type) @router.delete("/") @web_try() @sxtimeit def delete_constants(type: str, value: str, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)): return crud.delete_constant(db, type, value)