constants.py 991 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. from fastapi import Depends
  2. from sqlalchemy.orm import Session
  3. from fastapi import APIRouter
  4. from app.common.decorators import verify_all
  5. from constants.constants import CONSTANTS
  6. from utils import *
  7. import app.crud as crud
  8. from app import get_db
  9. router = APIRouter(
  10. prefix="/jpt/constants",
  11. tags=["constants-常量管理"],
  12. )
  13. def format_constants(constants: dict):
  14. return [{'id': k, 'value': v} for k, v in constants.items()]
  15. @router.get("/datasources", dependencies=[Depends(verify_all)])
  16. @web_try()
  17. @sxtimeit
  18. def get_datasources():
  19. return format_constants(CONSTANTS['DATASOURCES'])
  20. @router.get("/", dependencies=[Depends(verify_all)])
  21. @web_try()
  22. @sxtimeit
  23. def get_constants(type: str,db: Session = Depends(get_db)):
  24. return crud.get_constant_list(db, type)
  25. @router.delete("/", dependencies=[Depends(verify_all)])
  26. @web_try()
  27. @sxtimeit
  28. def delete_constants(type: str, value: str, db: Session = Depends(get_db)):
  29. return crud.delete_constant(db, type, value)