project.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import time
  2. from typing import Optional
  3. from fastapi import APIRouter
  4. from fastapi import Depends
  5. from sqlalchemy.orm import Session
  6. from app.utils.utils import *
  7. from utils.sx_time import sxtimeit
  8. from utils.sx_web import web_try
  9. from app.common.decorators import verify_special, verify_super_and_project, verify_user, verify_all, verify_super_admin
  10. from configs.globals import g
  11. from app import crud, get_db, get_page, schemas
  12. router = APIRouter(
  13. prefix="/jpt/project",
  14. tags=["project-项目管理"],
  15. )
  16. @router.post("/create_project", dependencies=[Depends(verify_super_admin)])
  17. @web_try()
  18. @sxtimeit
  19. def create_project(item: schemas.ProjectCreate, db: Session = Depends(get_db)):
  20. return crud.create_project(db,item)
  21. @router.put("/update_project", dependencies=[Depends(verify_super_and_project)])
  22. @web_try()
  23. @sxtimeit
  24. def update_project(item: schemas.ProjectUpdate, db: Session = Depends(get_db)):
  25. return crud.update_project(db,item)
  26. @router.get("", dependencies=[Depends(verify_user)])
  27. @web_try()
  28. @sxtimeit
  29. def get_projects(db: Session = Depends(get_db)):
  30. return crud.get_project_list(db,g.user_id)
  31. @router.get("/share_projects", dependencies=[Depends(verify_special)])
  32. @web_try()
  33. @sxtimeit
  34. def get_share_projects(db: Session = Depends(get_db)):
  35. return crud.get_share_projects(db)
  36. @router.get("/switch", dependencies=[Depends(verify_user)])
  37. @web_try()
  38. @sxtimeit
  39. def switch_project(project_id: int, db: Session = Depends(get_db)):
  40. return crud.switch_project_by_user(db,project_id,g.user_id)
  41. @router.get("/info", dependencies=[Depends(verify_all)])
  42. @web_try()
  43. @sxtimeit
  44. def get_project_info(project_id: int, db: Session = Depends(get_db)):
  45. return crud.get_project_info(db,project_id)