No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

route_fuelingtask.py 2.5 KiB

hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
hace 1 año
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. from fastapi import Depends, APIRouter, HTTPException, status
  2. from sqlalchemy.orm import Session
  3. from db.session import get_db
  4. from db.repository.fuelingtask import (
  5. create_fueling_task,
  6. delete_fueling_task,
  7. get_fueling_task_by_id
  8. )
  9. from schemas.fuelingtask import CreateFuelingTask, OutputFuelingTask
  10. from db.models.user import User
  11. from apis.v1.route_auth import get_current_user
  12. router = APIRouter()
  13. @router.post("/", response_model=OutputFuelingTask, status_code=status.HTTP_201_CREATED)
  14. def create_fuelingtask(
  15. fuelingtask: CreateFuelingTask = Depends(),
  16. db: Session = Depends(get_db),
  17. current_user: User = Depends(get_current_user),
  18. ):
  19. if current_user.Role != "FuelingPerson" and current_user.Role != "Admin":
  20. raise HTTPException(
  21. status_code=403, detail="You are not authorized to perform this action"
  22. )
  23. fuelingtask_res = create_fueling_task(
  24. fueling_task=fuelingtask, current_user=current_user.Id, db=db
  25. )
  26. print("Created FuelTask")
  27. if fuelingtask_res == "nodriver":
  28. raise HTTPException(
  29. status_code=404, detail="Driver ID not found"
  30. )
  31. if fuelingtask_res == "novehicle":
  32. raise HTTPException(
  33. status_code=404, detail="Vehicle ID not found"
  34. )
  35. return fuelingtask_res
  36. @router.get("/{fueling_task_id}", response_model=OutputFuelingTask, status_code=status.HTTP_200_OK)
  37. def get_fuelingtask(
  38. fueling_task_id: int,
  39. db: Session = Depends(get_db),
  40. current_user: User = Depends(get_current_user),
  41. ):
  42. if current_user.Role != "FuelingPerson" and current_user.Role != "Admin":
  43. raise HTTPException(
  44. status_code=403, detail="You are not authorized to perform this action"
  45. )
  46. fuelingtask = get_fueling_task_by_id(fueling_task_id, db)
  47. if fuelingtask == "notfound":
  48. raise HTTPException(
  49. status_code=404, detail="fuck off"
  50. )
  51. return fuelingtask
  52. @router.delete("/{fueling_task_id}", status_code=status.HTTP_204_NO_CONTENT)
  53. def delete_fuelingtask(
  54. fueling_task_id: int,
  55. db: Session = Depends(get_db),
  56. current_user: User = Depends(get_current_user),
  57. ):
  58. if current_user.Role != "FuelingPerson" and current_user.Role != "Admin":
  59. raise HTTPException(
  60. status_code=403, detail="You are not authorized to perform this action"
  61. )
  62. if not delete_fueling_task(fueling_task_id, db):
  63. raise HTTPException(
  64. status_code=404, detail="Fueling task not found"
  65. )