Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

route_report.py 856 B

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