constants.py 838 B

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