constants.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from fastapi import Depends, Header
  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)
  30. @router.get("/task_images")
  31. @web_try()
  32. @sxtimeit
  33. def get_task_images(language: str, type: int, auth_token: str = Header(), token_data: schemas.TokenData = Depends(verify_users)):
  34. return crud.get_task_images(language, type, auth_token)
  35. @router.get("/image_version")
  36. @web_try()
  37. @sxtimeit
  38. def get_image_version(image_id: str, auth_token: str = Header(), token_data: schemas.TokenData = Depends(verify_users)):
  39. return crud.get_image_version(image_id,auth_token)