123456789101112131415161718192021222324252627282930313233343536373839 |
- from fastapi import Depends
- from sqlalchemy.orm import Session
- from fastapi import APIRouter
- from app.common.decorators import verify_all
- from constants.constants import CONSTANTS
- from utils import *
- import app.crud as crud
- from app import get_db
- 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", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def get_datasources():
- return format_constants(CONSTANTS['DATASOURCES'])
- @router.get("/", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def get_constants(type: str,db: Session = Depends(get_db)):
- return crud.get_constant_list(db, type)
- @router.delete("/", dependencies=[Depends(verify_all)])
- @web_try()
- @sxtimeit
- def delete_constants(type: str, value: str, db: Session = Depends(get_db)):
- return crud.delete_constant(db, type, value)
|