Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

route_report.py 856 B

11 mesi fa
12345678910111213141516171819202122
  1. from fastapi import Depends, APIRouter, HTTPException, status
  2. from requests import Session
  3. from apis.v1.route_auth import get_current_user
  4. from db.models.user import User
  5. from db.repository.report import get_repot_jobsdone_by_driver
  6. from db.session import get_db
  7. router = APIRouter()
  8. @router.get("/jobsdone/{driver_id}", status_code=status.HTTP_200_OK)
  9. def get_report_jobsdone(driver_id: int, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
  10. if current_user.Role != "Admin":
  11. raise HTTPException(
  12. status_code=403, detail="You are not authorized to perform this action"
  13. )
  14. report = get_repot_jobsdone_by_driver(driver_id, db)
  15. if report == "notdriver":
  16. raise HTTPException(
  17. status_code=404, detail=f"Driver with id {driver_id} not found"
  18. )
  19. return report