@@ -33,7 +33,6 @@ def create_fuelingtask( | |||||
fuelingtask_res = create_fueling_task( | fuelingtask_res = create_fueling_task( | ||||
fueling_task=fuelingtask, current_user=current_user.Id, db=db | fueling_task=fuelingtask, current_user=current_user.Id, db=db | ||||
) | ) | ||||
print("Created FuelTask") | |||||
if fuelingtask_res == "nodriver": | if fuelingtask_res == "nodriver": | ||||
raise HTTPException(status_code=404, detail="Driver ID not found") | raise HTTPException(status_code=404, detail="Driver ID not found") | ||||
@@ -50,9 +50,7 @@ def create_carpart( | |||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, detail="You are not authorized to perform this action" | status_code=403, detail="You are not authorized to perform this action" | ||||
) | ) | ||||
print("So it begins...") | |||||
car_part_res = create_car_part(car_part=car_part, db=db) | car_part_res = create_car_part(car_part=car_part, db=db) | ||||
print("So it ends...") | |||||
return car_part_res | return car_part_res | ||||
@@ -88,7 +86,6 @@ def get_maintenancejob( | |||||
raise HTTPException( | raise HTTPException( | ||||
status_code=404, detail="Maintenance job with this id does not exist" | status_code=404, detail="Maintenance job with this id does not exist" | ||||
) | ) | ||||
print(maintenancejob) | |||||
return maintenancejob | return maintenancejob | ||||
@@ -170,7 +170,6 @@ def getMyRoutes( | |||||
db: Session = Depends(get_db), | db: Session = Depends(get_db), | ||||
current_user: User = Depends(get_current_user), | current_user: User = Depends(get_current_user), | ||||
): | ): | ||||
print("here") | |||||
if current_user.Role != "Driver": | if current_user.Role != "Driver": | ||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, | status_code=403, | ||||
@@ -106,7 +106,6 @@ def get_user_me( | |||||
current_user: Annotated[User, Depends(get_current_user)], | current_user: Annotated[User, Depends(get_current_user)], | ||||
db: Annotated[Session, Depends(get_db)], | db: Annotated[Session, Depends(get_db)], | ||||
): | ): | ||||
print("Getting current user...") | |||||
return current_user | return current_user | ||||
@@ -25,7 +25,6 @@ async def create_vehicle( | |||||
db: Session = Depends(get_db), | db: Session = Depends(get_db), | ||||
current_user: User = Depends(get_current_user), | current_user: User = Depends(get_current_user), | ||||
): | ): | ||||
print(current_user.Role) | |||||
if current_user.Role != "Admin": | if current_user.Role != "Admin": | ||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, detail="You are not authorized to perform this action" | status_code=403, detail="You are not authorized to perform this action" | ||||
@@ -132,7 +131,11 @@ def update_vehicle( | |||||
db: Session = Depends(get_db), | db: Session = Depends(get_db), | ||||
current_user: User = Depends(get_current_user), | current_user: User = Depends(get_current_user), | ||||
): | ): | ||||
if current_user.Role != "Admin" and current_user.Role != "Maintenance": | |||||
if ( | |||||
current_user.Role != "Admin" | |||||
and current_user.Role != "Maintenance" | |||||
and current_user.Role != "Fueling" | |||||
): | |||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, detail="You are not authorized to perform this action" | status_code=403, detail="You are not authorized to perform this action" | ||||
) | ) | ||||
@@ -169,8 +172,6 @@ def update_vehicle_location( | |||||
current_user: User = Depends(get_current_user), | current_user: User = Depends(get_current_user), | ||||
db: Session = Depends(get_db), | db: Session = Depends(get_db), | ||||
): | ): | ||||
print(current_user) | |||||
print(current_user.Name) | |||||
if current_user.Role != "Driver" and current_user.Role != "Admin": | if current_user.Role != "Driver" and current_user.Role != "Admin": | ||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, detail="You are not authorized to perform this action" | status_code=403, detail="You are not authorized to perform this action" | ||||
@@ -179,7 +180,6 @@ def update_vehicle_location( | |||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, detail="You are not the correct car driver" | status_code=403, detail="You are not the correct car driver" | ||||
) | ) | ||||
print("FUNNY") | |||||
vehicle = update_vehicle_geoloc(vehicle_id=vehicle_id, location=location, db=db) | vehicle = update_vehicle_geoloc(vehicle_id=vehicle_id, location=location, db=db) | ||||
if vehicle == "vehiclenotfound": | if vehicle == "vehiclenotfound": | ||||
raise HTTPException(status_code=404, detail="Vehicle not found") | raise HTTPException(status_code=404, detail="Vehicle not found") | ||||
@@ -6,6 +6,7 @@ from db.repository.vehicle import get_vehicle_by_id | |||||
def get_all_auctions(db: Session): | def get_all_auctions(db: Session): | ||||
print("Retrieving all auctions") | |||||
auctions = db.query(Auction).all() | auctions = db.query(Auction).all() | ||||
for auction in auctions: | for auction in auctions: | ||||
auction.car = auction.vehicle | auction.car = auction.vehicle | ||||
@@ -13,6 +14,7 @@ def get_all_auctions(db: Session): | |||||
def get_auction_by_id(id: int, db: Session): | def get_auction_by_id(id: int, db: Session): | ||||
print("Retrieving auction by id: " + str(id)) | |||||
auction = db.query(Auction).filter(Auction.Id == id).first() | auction = db.query(Auction).filter(Auction.Id == id).first() | ||||
if not auction: | if not auction: | ||||
return None | return None | ||||
@@ -21,6 +23,7 @@ def get_auction_by_id(id: int, db: Session): | |||||
def create_new_auction(auction: CreateAuction, createId: int, db: Session): | def create_new_auction(auction: CreateAuction, createId: int, db: Session): | ||||
print("Creating new auction" + str(auction) + " by user " + str(createId)) | |||||
vehicle = get_vehicle_by_id(auction.carId, db) | vehicle = get_vehicle_by_id(auction.carId, db) | ||||
if vehicle is None: | if vehicle is None: | ||||
return "novehicle" | return "novehicle" | ||||
@@ -39,6 +42,7 @@ def create_new_auction(auction: CreateAuction, createId: int, db: Session): | |||||
def delete_auction_by_id(id: int, db: Session): | def delete_auction_by_id(id: int, db: Session): | ||||
print("Deleting auction by id: " + str(id)) | |||||
auction = db.query(Auction).filter(Auction.Id == id).first() | auction = db.query(Auction).filter(Auction.Id == id).first() | ||||
if not auction: | if not auction: | ||||
return "noauction" | return "noauction" | ||||
@@ -48,6 +52,7 @@ def delete_auction_by_id(id: int, db: Session): | |||||
def edit_auction_by_id(id: int, auction: CreateAuction, db: Session): | def edit_auction_by_id(id: int, auction: CreateAuction, db: Session): | ||||
print("Editing auction by id: " + str(id) + " with data: " + str(auction)) | |||||
auction_db = db.query(Auction).filter(Auction.Id == id) | auction_db = db.query(Auction).filter(Auction.Id == id) | ||||
auction_object = auction_db.first() | auction_object = auction_db.first() | ||||
if not auction_object: | if not auction_object: | ||||
@@ -7,6 +7,7 @@ from db.repository.user import get_user_by_id | |||||
def create_new_task(task: CreateTask, db: Session): | def create_new_task(task: CreateTask, db: Session): | ||||
print("Creating new task" + str(task) + " by user " + str(task.DriverId)) | |||||
driver = get_user_by_id(task.DriverId, "Driver", db) | driver = get_user_by_id(task.DriverId, "Driver", db) | ||||
if not driver: | if not driver: | ||||
return "notdriver" | return "notdriver" | ||||
@@ -26,6 +27,7 @@ def create_new_task(task: CreateTask, db: Session): | |||||
def change_task_status(task_id: int, status: str, distance: int, db: Session): | def change_task_status(task_id: int, status: str, distance: int, db: Session): | ||||
print("Changing task status to " + status + " for task " + str(task_id)) | |||||
task = db.query(DriveTask).filter(DriveTask.Id == task_id).first() | task = db.query(DriveTask).filter(DriveTask.Id == task_id).first() | ||||
if not task: | if not task: | ||||
return "notaskfound" | return "notaskfound" | ||||
@@ -11,6 +11,12 @@ from db.repository.vehicle import get_vehicle_by_id | |||||
def create_fueling_task( | def create_fueling_task( | ||||
fueling_task: CreateFuelingTask, current_user: int, db: Session | fueling_task: CreateFuelingTask, current_user: int, db: Session | ||||
): | ): | ||||
print( | |||||
"Creating new fueling task" | |||||
+ str(fueling_task) | |||||
+ " by user " | |||||
+ str(current_user) | |||||
) | |||||
if not get_vehicle_by_id(fueling_task.VehicleId, db=db): | if not get_vehicle_by_id(fueling_task.VehicleId, db=db): | ||||
return "novehicle" | return "novehicle" | ||||
@@ -33,7 +39,6 @@ def create_fueling_task( | |||||
db.add(fueling_task_object) | db.add(fueling_task_object) | ||||
db.commit() | db.commit() | ||||
db.refresh(fueling_task_object) | db.refresh(fueling_task_object) | ||||
print(driver.__dict__) | |||||
driverobj = driver.__dict__ | driverobj = driver.__dict__ | ||||
driverobj["AssignedVehicle"] = driver.vehicle.__dict__ | driverobj["AssignedVehicle"] = driver.vehicle.__dict__ | ||||
resobj = fueling_task_object.__dict__ | resobj = fueling_task_object.__dict__ | ||||
@@ -50,6 +55,7 @@ def create_fueling_task( | |||||
def delete_fueling_task(fueling_task_id: int, db: Session): | def delete_fueling_task(fueling_task_id: int, db: Session): | ||||
print("Deleting fueling task by id: " + str(fueling_task_id)) | |||||
fueling_task = ( | fueling_task = ( | ||||
db.query(FuelingTask).filter(FuelingTask.Id == fueling_task_id).first() | db.query(FuelingTask).filter(FuelingTask.Id == fueling_task_id).first() | ||||
) | ) | ||||
@@ -61,6 +67,7 @@ def delete_fueling_task(fueling_task_id: int, db: Session): | |||||
def get_fueling_task_by_id(fuel_task_id: int, db: Session): | def get_fueling_task_by_id(fuel_task_id: int, db: Session): | ||||
print("Retrieving fueling task by id: " + str(fuel_task_id)) | |||||
fuel_task = db.query(FuelingTask).filter(FuelingTask.Id == fuel_task_id).first() | fuel_task = db.query(FuelingTask).filter(FuelingTask.Id == fuel_task_id).first() | ||||
if not fuel_task: | if not fuel_task: | ||||
return "notfound" | return "notfound" | ||||
@@ -80,6 +87,7 @@ def get_fueling_task_by_id(fuel_task_id: int, db: Session): | |||||
def get_all_fueling_tasks(db: Session): | def get_all_fueling_tasks(db: Session): | ||||
print("Retrieving all fueling tasks") | |||||
fuel_task = db.query(FuelingTask).all() | fuel_task = db.query(FuelingTask).all() | ||||
result = [] | result = [] | ||||
for task in fuel_task: | for task in fuel_task: | ||||
@@ -7,11 +7,10 @@ from db.models.carpart import CarPart | |||||
from db.repository.user import get_car_driver | from db.repository.user import get_car_driver | ||||
def create_new_maintenancejob( | |||||
maintenancejob: CreateMaintenanceJob, db: Session | |||||
): | |||||
def create_new_maintenancejob(maintenancejob: CreateMaintenanceJob, db: Session): | |||||
print("Creating new maintenance job" + str(maintenancejob)) | |||||
vehicledriver = get_car_driver(maintenancejob.VehicleID, db) | vehicledriver = get_car_driver(maintenancejob.VehicleID, db) | ||||
if (vehicledriver != False): | |||||
if vehicledriver != False: | |||||
vehicledriver = vehicledriver.Id | vehicledriver = vehicledriver.Id | ||||
else: | else: | ||||
return "nodriver" | return "nodriver" | ||||
@@ -30,6 +29,7 @@ def create_new_maintenancejob( | |||||
def create_car_part(car_part: CreateCarPart, db: Session): | def create_car_part(car_part: CreateCarPart, db: Session): | ||||
print("Creating new car part" + str(car_part)) | |||||
car_part_object = CarPart( | car_part_object = CarPart( | ||||
ParentId=car_part.ParentId, | ParentId=car_part.ParentId, | ||||
Name=car_part.Name, | Name=car_part.Name, | ||||
@@ -50,6 +50,7 @@ def create_car_part(car_part: CreateCarPart, db: Session): | |||||
def calculate_total_cost(car_parts: CarPart): | def calculate_total_cost(car_parts: CarPart): | ||||
print("Calculating total cost") | |||||
total_cost = 0 | total_cost = 0 | ||||
for part in car_parts: | for part in car_parts: | ||||
total_cost += part.Cost | total_cost += part.Cost | ||||
@@ -57,14 +58,12 @@ def calculate_total_cost(car_parts: CarPart): | |||||
def get_all_maintenance_jobs(db: Session): | def get_all_maintenance_jobs(db: Session): | ||||
print("Getting all maintenance jobs") | |||||
maintenancejobs = db.query(MaintenanceJob).all() | maintenancejobs = db.query(MaintenanceJob).all() | ||||
print("DB Access complete") | |||||
result = [] | result = [] | ||||
for job in maintenancejobs: | for job in maintenancejobs: | ||||
job_dict = job.__dict__ | job_dict = job.__dict__ | ||||
print(job_dict) | |||||
job_dict["CarPartsList"] = [part.__dict__ for part in job.CarParts] | job_dict["CarPartsList"] = [part.__dict__ for part in job.CarParts] | ||||
print(len(job_dict["CarPartsList"])) | |||||
for part in job_dict["CarPartsList"]: | for part in job_dict["CarPartsList"]: | ||||
if (part["ImageURL"] is None) or (part["ImageURL"] == ""): | if (part["ImageURL"] is None) or (part["ImageURL"] == ""): | ||||
part["image"] = "" | part["image"] = "" | ||||
@@ -75,11 +74,11 @@ def get_all_maintenance_jobs(db: Session): | |||||
job_dict["FinishedBy"] = job.FinishedBy.__dict__ | job_dict["FinishedBy"] = job.FinishedBy.__dict__ | ||||
job_dict["Vehicle"] = job.Vehicle.__dict__ | job_dict["Vehicle"] = job.Vehicle.__dict__ | ||||
result.append(job_dict) | result.append(job_dict) | ||||
print("Returning...") | |||||
return maintenancejobs | return maintenancejobs | ||||
def get_maintenance_job(maintenancejob_id: int, db: Session): | def get_maintenance_job(maintenancejob_id: int, db: Session): | ||||
print("Getting maintenance job by id: " + str(maintenancejob_id)) | |||||
maintenancejob = ( | maintenancejob = ( | ||||
db.query(MaintenanceJob).filter(MaintenanceJob.Id == maintenancejob_id).first() | db.query(MaintenanceJob).filter(MaintenanceJob.Id == maintenancejob_id).first() | ||||
) | ) | ||||
@@ -96,17 +95,26 @@ def get_maintenance_job(maintenancejob_id: int, db: Session): | |||||
if maintenancejob.Status == "Complete": | if maintenancejob.Status == "Complete": | ||||
res["FinishedBy"] = maintenancejob.FinishedBy.__dict__ | res["FinishedBy"] = maintenancejob.FinishedBy.__dict__ | ||||
res["Vehicle"] = maintenancejob.Vehicle.__dict__ | res["Vehicle"] = maintenancejob.Vehicle.__dict__ | ||||
print("DB Access complete") | |||||
return maintenancejob | return maintenancejob | ||||
def change_maintenance_status(maintenancejob_id: int, status: str, worker_id: int, db: Session): | |||||
def change_maintenance_status( | |||||
maintenancejob_id: int, status: str, worker_id: int, db: Session | |||||
): | |||||
print( | |||||
"Changing maintenance job status to " | |||||
+ status | |||||
+ " for job " | |||||
+ str(maintenancejob_id) | |||||
+ " by worker " | |||||
+ str(worker_id) | |||||
) | |||||
maintenancejob = ( | maintenancejob = ( | ||||
db.query(MaintenanceJob).filter(MaintenanceJob.Id == maintenancejob_id).first() | db.query(MaintenanceJob).filter(MaintenanceJob.Id == maintenancejob_id).first() | ||||
) | ) | ||||
if maintenancejob is None: | if maintenancejob is None: | ||||
return None | return None | ||||
if (status == "Complete"): | |||||
if status == "Complete": | |||||
maintenancejob.MaintenanceWorker = worker_id | maintenancejob.MaintenanceWorker = worker_id | ||||
maintenancejob.Status = status | maintenancejob.Status = status | ||||
db.commit() | db.commit() | ||||
@@ -114,6 +122,3 @@ def change_maintenance_status(maintenancejob_id: int, status: str, worker_id: in | |||||
return maintenancejob | return maintenancejob | ||||
else: | else: | ||||
return None | return None | ||||
@@ -128,8 +128,6 @@ def get_pdf(driver_id: int, db: Session): | |||||
content.append(title) | content.append(title) | ||||
content.append(Paragraph("<br/>", title_style)) | content.append(Paragraph("<br/>", title_style)) | ||||
print(report_data["Driver"]) | |||||
# Add detailed information about the driver | # Add detailed information about the driver | ||||
driver_info = [ | driver_info = [ | ||||
["Driver Name", report_data["Driver"]["Name"]], | ["Driver Name", report_data["Driver"]["Name"]], | ||||
@@ -152,7 +150,6 @@ def get_pdf(driver_id: int, db: Session): | |||||
content.append(Paragraph("<br/><br/>", title_style)) | content.append(Paragraph("<br/><br/>", title_style)) | ||||
vehicle = report_data["Driver"]["AssignedVehicle"].__dict__ | vehicle = report_data["Driver"]["AssignedVehicle"].__dict__ | ||||
print(vehicle) | |||||
if ( | if ( | ||||
vehicle["CurrentLocation"] is None | vehicle["CurrentLocation"] is None | ||||
or vehicle["CurrentLocation"] == "" | or vehicle["CurrentLocation"] == "" | ||||
@@ -9,6 +9,7 @@ from db.models.drivetask import DriveTask | |||||
def create_new_user(user: UserCreate, db: Session): | def create_new_user(user: UserCreate, db: Session): | ||||
print("Creating new user" + str(user)) | |||||
if get_user_by_email(user.Email, db): | if get_user_by_email(user.Email, db): | ||||
return "userExists" | return "userExists" | ||||
user_object = User( | user_object = User( | ||||
@@ -29,6 +30,7 @@ def create_new_user(user: UserCreate, db: Session): | |||||
def create_new_driver(driver: DriverCreate, db: Session): | def create_new_driver(driver: DriverCreate, db: Session): | ||||
print("Creating new driver" + str(driver)) | |||||
if get_user_by_email(driver.Email, db): | if get_user_by_email(driver.Email, db): | ||||
return "userExists" | return "userExists" | ||||
driver_object = User( | driver_object = User( | ||||
@@ -50,6 +52,7 @@ def create_new_driver(driver: DriverCreate, db: Session): | |||||
def get_user_by_id(user_id: int, role: str, db: Session): | def get_user_by_id(user_id: int, role: str, db: Session): | ||||
print("Retrieving user by id: " + str(user_id)) | |||||
user = db.query(User).filter(User.Id == user_id).first() | user = db.query(User).filter(User.Id == user_id).first() | ||||
if not user: | if not user: | ||||
return False | return False | ||||
@@ -59,16 +62,19 @@ def get_user_by_id(user_id: int, role: str, db: Session): | |||||
def get_user_by_email(email: str, db: Session): | def get_user_by_email(email: str, db: Session): | ||||
print("Retrieving user by email: " + str(email)) | |||||
user = db.query(User).filter(User.Email == email).first() | user = db.query(User).filter(User.Email == email).first() | ||||
return user | return user | ||||
def get_user_by_phone(phone: str, db: Session): | def get_user_by_phone(phone: str, db: Session): | ||||
print("Retrieving user by phone: " + str(phone)) | |||||
user = db.query(User).filter(User.ContactNumber == phone).first() | user = db.query(User).filter(User.ContactNumber == phone).first() | ||||
return user | return user | ||||
def verify_driver_exists(driver_id: int, db: Session): | def verify_driver_exists(driver_id: int, db: Session): | ||||
print("Verifying driver exists: " + str(driver_id)) | |||||
driver = db.query(User).filter(User.Id == driver_id).first() | driver = db.query(User).filter(User.Id == driver_id).first() | ||||
if not driver: | if not driver: | ||||
return False | return False | ||||
@@ -78,6 +84,7 @@ def verify_driver_exists(driver_id: int, db: Session): | |||||
def get_car_driver(vehicle_id: int, db: Session): | def get_car_driver(vehicle_id: int, db: Session): | ||||
print("Retrieving driver for vehicle: " + str(vehicle_id)) | |||||
driver = db.query(User).filter(User.AssignedVehicle == vehicle_id).first() | driver = db.query(User).filter(User.AssignedVehicle == vehicle_id).first() | ||||
if not driver: | if not driver: | ||||
return False | return False | ||||
@@ -85,6 +92,7 @@ def get_car_driver(vehicle_id: int, db: Session): | |||||
def list_users(db: Session, role: str = "Any"): | def list_users(db: Session, role: str = "Any"): | ||||
print("Listing users") | |||||
users = db.query(User).filter((User.Role == role) | (role == "Any")).all() | users = db.query(User).filter((User.Role == role) | (role == "Any")).all() | ||||
return users | return users | ||||
@@ -92,6 +100,7 @@ def list_users(db: Session, role: str = "Any"): | |||||
def get_users_by_name( | def get_users_by_name( | ||||
db: Session, name: str = "", role: str = None, page: int = 1, per_page: int = 20 | db: Session, name: str = "", role: str = None, page: int = 1, per_page: int = 20 | ||||
): | ): | ||||
print("Listing users by name") | |||||
if role == "Admin": | if role == "Admin": | ||||
return None | return None | ||||
if role is None: | if role is None: | ||||
@@ -103,6 +112,7 @@ def get_users_by_name( | |||||
def replace_user_data(user_id: int, user_data: UserCreate, db: Session): | def replace_user_data(user_id: int, user_data: UserCreate, db: Session): | ||||
print("Replacing user data" + str(user_data) + " for user id: " + str(user_id)) | |||||
user = db.query(User).filter(User.Id == user_id).first() | user = db.query(User).filter(User.Id == user_id).first() | ||||
if not user: | if not user: | ||||
return "userNotFound" | return "userNotFound" | ||||
@@ -121,6 +131,7 @@ def replace_user_data(user_id: int, user_data: UserCreate, db: Session): | |||||
def delete_user_data(id: int, db: Session): | def delete_user_data(id: int, db: Session): | ||||
print("Deleting user by id: " + str(id)) | |||||
user = db.query(User).filter(User.Id == id).first() | user = db.query(User).filter(User.Id == id).first() | ||||
if not user: | if not user: | ||||
return "userNotFound" | return "userNotFound" | ||||
@@ -6,6 +6,7 @@ from db.repository.user import get_car_driver | |||||
def create_new_vehicle(vehicle: CreateVehicle, db: Session): | def create_new_vehicle(vehicle: CreateVehicle, db: Session): | ||||
print("Creating new vehicle" + str(vehicle)) | |||||
vehicle_object = Vehicle( | vehicle_object = Vehicle( | ||||
**vehicle.model_dump(), Fuel=0, Status="Inactive", CurrentLocation=[] | **vehicle.model_dump(), Fuel=0, Status="Inactive", CurrentLocation=[] | ||||
) | ) | ||||
@@ -16,6 +17,7 @@ def create_new_vehicle(vehicle: CreateVehicle, db: Session): | |||||
def update_vehicle_geoloc(vehicle_id: int, location: VehicleLocation, db: Session): | def update_vehicle_geoloc(vehicle_id: int, location: VehicleLocation, db: Session): | ||||
print("Updating vehicle geolocation" + str(location)) | |||||
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == vehicle_id) | vehicle_db = db.query(Vehicle).filter(Vehicle.Id == vehicle_id) | ||||
vehicle_object = vehicle_db.first() | vehicle_object = vehicle_db.first() | ||||
if not vehicle_object: | if not vehicle_object: | ||||
@@ -29,13 +31,13 @@ def update_vehicle_geoloc(vehicle_id: int, location: VehicleLocation, db: Sessio | |||||
def assign_vehicle_driver(vehicle_id: int, driver_id: int, db: Session): | def assign_vehicle_driver(vehicle_id: int, driver_id: int, db: Session): | ||||
print("Assigning vehicle " + str(vehicle_id) + " to driver " + str(driver_id)) | |||||
if driver_id != None: | if driver_id != None: | ||||
driver = ( | driver = ( | ||||
db.query(User) | db.query(User) | ||||
.filter((User.Id == driver_id) & (User.Role == "Driver")) | .filter((User.Id == driver_id) & (User.Role == "Driver")) | ||||
.first() | .first() | ||||
) | ) | ||||
print(driver) | |||||
vehicle = db.query(Vehicle).filter(Vehicle.Id == vehicle_id).first() | vehicle = db.query(Vehicle).filter(Vehicle.Id == vehicle_id).first() | ||||
if not vehicle: | if not vehicle: | ||||
return "novehicle" | return "novehicle" | ||||
@@ -59,6 +61,7 @@ def assign_vehicle_driver(vehicle_id: int, driver_id: int, db: Session): | |||||
def list_vehicles(db: Session): | def list_vehicles(db: Session): | ||||
print("Listing vehicles") | |||||
vehicles = db.query(Vehicle).all() | vehicles = db.query(Vehicle).all() | ||||
# assign AssignedDriver to all vehicles based on their drivers | # assign AssignedDriver to all vehicles based on their drivers | ||||
for vehicle in vehicles: | for vehicle in vehicles: | ||||
@@ -71,6 +74,7 @@ def list_vehicles(db: Session): | |||||
def get_vehicle_by_id(vehicle_id: int, db: Session): | def get_vehicle_by_id(vehicle_id: int, db: Session): | ||||
print("Retrieving vehicle by id: " + str(vehicle_id)) | |||||
vehicle = db.query(Vehicle).filter(Vehicle.Id == vehicle_id).first() | vehicle = db.query(Vehicle).filter(Vehicle.Id == vehicle_id).first() | ||||
if not vehicle: | if not vehicle: | ||||
return None | return None | ||||
@@ -83,6 +87,7 @@ def get_vehicle_by_id(vehicle_id: int, db: Session): | |||||
def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session): | def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session): | ||||
print("Replacing vehicle data for vehicle " + str(id) + " with " + str(vehicle)) | |||||
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id) | vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id) | ||||
vehicle_object = vehicle_db.first() | vehicle_object = vehicle_db.first() | ||||
if not vehicle_object: | if not vehicle_object: | ||||
@@ -100,7 +105,6 @@ def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session): | |||||
# return "driverNotFound" | # return "driverNotFound" | ||||
vehicle_object.Capacity = vehicle.Capacity | vehicle_object.Capacity = vehicle.Capacity | ||||
vehicle_object.Year = vehicle.Year | vehicle_object.Year = vehicle.Year | ||||
print(vehicle_object) | |||||
db.add(vehicle_object) | db.add(vehicle_object) | ||||
db.commit() | db.commit() | ||||
# vehicle_object.AssignedDriver = vehicle.AssignedDriver | # vehicle_object.AssignedDriver = vehicle.AssignedDriver | ||||
@@ -108,6 +112,7 @@ def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session): | |||||
def delete_vehicle_data(id: int, db: Session): | def delete_vehicle_data(id: int, db: Session): | ||||
print("Deleting vehicle data for vehicle " + str(id)) | |||||
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id) | vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id) | ||||
vehicle_object = vehicle_db.first() | vehicle_object = vehicle_db.first() | ||||
if not vehicle_object: | if not vehicle_object: | ||||