2 Commits

3 changed files with 34 additions and 0 deletions
Split View
  1. +1
    -0
      app/apis/base.py
  2. +15
    -0
      app/apis/v1/route_fuelingtask.py
  3. +18
    -0
      app/db/repository/fuelingtask.py

+ 1
- 0
app/apis/base.py View File

@@ -23,3 +23,4 @@ api_router.include_router(
api_router.include_router(route_fuelingtask.router, prefix="/fuel", tags=["fueltasks"])
api_router.include_router(route_auction.router, prefix="/auction", tags=["auctions"])
api_router.include_router(route_report.router, prefix="/report", tags=["reports"])


+ 15
- 0
app/apis/v1/route_fuelingtask.py View File

@@ -6,6 +6,7 @@ from db.repository.fuelingtask import (
delete_fueling_task,
get_fueling_task_by_id,
get_all_fueling_tasks,
get_fuel_tasks_by_creator,
)
from schemas.fuelingtask import (
CreateFuelingTask,
@@ -87,3 +88,17 @@ def get_all(
)
tasks = get_all_fueling_tasks(db)
return tasks

@router.get("/creator/{creator_id}", response_model=OutputFuelingTaskList, status_code=status.HTTP_200_OK)
def get_fuel_tasks_by_creator_id(
creator_id: int,
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
if current_user.Role != "Admin" and current_user.Role != "Fueling":
raise HTTPException(
status_code=403, detail="You are not authorized to perform this action"
)

tasks = get_fuel_tasks_by_creator(creator_id, db)
return tasks

+ 18
- 0
app/db/repository/fuelingtask.py View File

@@ -102,3 +102,21 @@ def get_all_fueling_tasks(db: Session):
result.append(res)
x = {"FuelingTasks": result}
return x

def get_fuel_tasks_by_creator(creator_id: int, db: Session):
print(f"Retrieving all fueling tasks created by user ID: {creator_id}")
fueling_tasks = db.query(FuelingTask).filter(FuelingTask.CreatedById == creator_id).all()
result = []

for task in fueling_tasks:
res = task.__dict__
res["ImageBefore"] = None
res["ImageAfter"] = None
res["Creator"] = task.CreatedById
driver = get_user_by_id(task.DriverId, role="Driver", db=db)
driver_obj = driver.__dict__
res["Driver"] = driver_obj
res["Driver"]["AssignedVehicle"] = driver.vehicle
result.append(res)

return {"FuelingTasks": result}

Loading…
Cancel
Save