@@ -23,3 +23,4 @@ api_router.include_router( | |||||
api_router.include_router(route_fuelingtask.router, prefix="/fuel", tags=["fueltasks"]) | 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_auction.router, prefix="/auction", tags=["auctions"]) | ||||
api_router.include_router(route_report.router, prefix="/report", tags=["reports"]) | api_router.include_router(route_report.router, prefix="/report", tags=["reports"]) | ||||
@@ -6,6 +6,7 @@ from db.repository.fuelingtask import ( | |||||
delete_fueling_task, | delete_fueling_task, | ||||
get_fueling_task_by_id, | get_fueling_task_by_id, | ||||
get_all_fueling_tasks, | get_all_fueling_tasks, | ||||
get_fuel_tasks_by_creator, | |||||
) | ) | ||||
from schemas.fuelingtask import ( | from schemas.fuelingtask import ( | ||||
CreateFuelingTask, | CreateFuelingTask, | ||||
@@ -87,3 +88,17 @@ def get_all( | |||||
) | ) | ||||
tasks = get_all_fueling_tasks(db) | tasks = get_all_fueling_tasks(db) | ||||
return tasks | 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 |
@@ -102,3 +102,21 @@ def get_all_fueling_tasks(db: Session): | |||||
result.append(res) | result.append(res) | ||||
x = {"FuelingTasks": result} | x = {"FuelingTasks": result} | ||||
return x | 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} |