You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

23 lines
856 B

  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