constants.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from fastapi import Depends
  2. from sqlalchemy.orm import Session
  3. from fastapi import APIRouter
  4. from app.common.security.auth import verify_users
  5. from constants.constants import CONSTANTS
  6. from utils import *
  7. import app.crud as crud
  8. from app import get_db, schemas
  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")
  16. @web_try()
  17. @sxtimeit
  18. def get_datasources(token_data: schemas.TokenData = Depends(verify_users)):
  19. return format_constants(CONSTANTS['DATASOURCES'])
  20. @router.get("/")
  21. @web_try()
  22. @sxtimeit
  23. def get_constants(type: str,token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  24. return crud.get_constant_list(db, type)
  25. @router.delete("/")
  26. @web_try()
  27. @sxtimeit
  28. def delete_constants(type: str, value: str, token_data: schemas.TokenData = Depends(verify_users), db: Session = Depends(get_db)):
  29. return crud.delete_constant(db, type, value)