Browse Source

fixes, fueling, print

main
Madiwka3 1 year ago
parent
commit
236f349809
12 changed files with 58 additions and 31 deletions
  1. +0
    -1
      app/apis/v1/route_fuelingtask.py
  2. +0
    -3
      app/apis/v1/route_maintenancejob.py
  3. +0
    -1
      app/apis/v1/route_task.py
  4. +0
    -1
      app/apis/v1/route_user.py
  5. +5
    -5
      app/apis/v1/route_vehicle.py
  6. +5
    -0
      app/db/repository/auction.py
  7. +2
    -0
      app/db/repository/drivetask.py
  8. +9
    -1
      app/db/repository/fuelingtask.py
  9. +19
    -14
      app/db/repository/maintenancejob.py
  10. +0
    -3
      app/db/repository/report.py
  11. +11
    -0
      app/db/repository/user.py
  12. +7
    -2
      app/db/repository/vehicle.py

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

@@ -33,7 +33,6 @@ def create_fuelingtask(
fuelingtask_res = create_fueling_task(
fueling_task=fuelingtask, current_user=current_user.Id, db=db
)
print("Created FuelTask")
if fuelingtask_res == "nodriver":
raise HTTPException(status_code=404, detail="Driver ID not found")



+ 0
- 3
app/apis/v1/route_maintenancejob.py View File

@@ -50,9 +50,7 @@ def create_carpart(
raise HTTPException(
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)
print("So it ends...")
return car_part_res


@@ -88,7 +86,6 @@ def get_maintenancejob(
raise HTTPException(
status_code=404, detail="Maintenance job with this id does not exist"
)
print(maintenancejob)
return maintenancejob




+ 0
- 1
app/apis/v1/route_task.py View File

@@ -170,7 +170,6 @@ def getMyRoutes(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
print("here")
if current_user.Role != "Driver":
raise HTTPException(
status_code=403,


+ 0
- 1
app/apis/v1/route_user.py View File

@@ -106,7 +106,6 @@ def get_user_me(
current_user: Annotated[User, Depends(get_current_user)],
db: Annotated[Session, Depends(get_db)],
):
print("Getting current user...")
return current_user




+ 5
- 5
app/apis/v1/route_vehicle.py View File

@@ -25,7 +25,6 @@ async def create_vehicle(
db: Session = Depends(get_db),
current_user: User = Depends(get_current_user),
):
print(current_user.Role)
if current_user.Role != "Admin":
raise HTTPException(
status_code=403, detail="You are not authorized to perform this action"
@@ -132,7 +131,11 @@ def update_vehicle(
db: Session = Depends(get_db),
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(
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),
db: Session = Depends(get_db),
):
print(current_user)
print(current_user.Name)
if current_user.Role != "Driver" and current_user.Role != "Admin":
raise HTTPException(
status_code=403, detail="You are not authorized to perform this action"
@@ -179,7 +180,6 @@ def update_vehicle_location(
raise HTTPException(
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)
if vehicle == "vehiclenotfound":
raise HTTPException(status_code=404, detail="Vehicle not found")


+ 5
- 0
app/db/repository/auction.py View File

@@ -6,6 +6,7 @@ from db.repository.vehicle import get_vehicle_by_id


def get_all_auctions(db: Session):
print("Retrieving all auctions")
auctions = db.query(Auction).all()
for auction in auctions:
auction.car = auction.vehicle
@@ -13,6 +14,7 @@ def get_all_auctions(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()
if not auction:
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):
print("Creating new auction" + str(auction) + " by user " + str(createId))
vehicle = get_vehicle_by_id(auction.carId, db)
if vehicle is None:
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):
print("Deleting auction by id: " + str(id))
auction = db.query(Auction).filter(Auction.Id == id).first()
if not auction:
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):
print("Editing auction by id: " + str(id) + " with data: " + str(auction))
auction_db = db.query(Auction).filter(Auction.Id == id)
auction_object = auction_db.first()
if not auction_object:


+ 2
- 0
app/db/repository/drivetask.py View File

@@ -7,6 +7,7 @@ from db.repository.user import get_user_by_id


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)
if not driver:
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):
print("Changing task status to " + status + " for task " + str(task_id))
task = db.query(DriveTask).filter(DriveTask.Id == task_id).first()
if not task:
return "notaskfound"


+ 9
- 1
app/db/repository/fuelingtask.py View File

@@ -11,6 +11,12 @@ from db.repository.vehicle import get_vehicle_by_id
def create_fueling_task(
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):
return "novehicle"

@@ -33,7 +39,6 @@ def create_fueling_task(
db.add(fueling_task_object)
db.commit()
db.refresh(fueling_task_object)
print(driver.__dict__)
driverobj = driver.__dict__
driverobj["AssignedVehicle"] = driver.vehicle.__dict__
resobj = fueling_task_object.__dict__
@@ -50,6 +55,7 @@ def create_fueling_task(


def delete_fueling_task(fueling_task_id: int, db: Session):
print("Deleting fueling task by id: " + str(fueling_task_id))
fueling_task = (
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):
print("Retrieving fueling task by id: " + str(fuel_task_id))
fuel_task = db.query(FuelingTask).filter(FuelingTask.Id == fuel_task_id).first()
if not fuel_task:
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):
print("Retrieving all fueling tasks")
fuel_task = db.query(FuelingTask).all()
result = []
for task in fuel_task:


+ 19
- 14
app/db/repository/maintenancejob.py View File

@@ -7,11 +7,10 @@ from db.models.carpart import CarPart
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)
if (vehicledriver != False):
if vehicledriver != False:
vehicledriver = vehicledriver.Id
else:
return "nodriver"
@@ -30,6 +29,7 @@ def create_new_maintenancejob(


def create_car_part(car_part: CreateCarPart, db: Session):
print("Creating new car part" + str(car_part))
car_part_object = CarPart(
ParentId=car_part.ParentId,
Name=car_part.Name,
@@ -50,6 +50,7 @@ def create_car_part(car_part: CreateCarPart, db: Session):


def calculate_total_cost(car_parts: CarPart):
print("Calculating total cost")
total_cost = 0
for part in car_parts:
total_cost += part.Cost
@@ -57,14 +58,12 @@ def calculate_total_cost(car_parts: CarPart):


def get_all_maintenance_jobs(db: Session):
print("Getting all maintenance jobs")
maintenancejobs = db.query(MaintenanceJob).all()
print("DB Access complete")
result = []
for job in maintenancejobs:
job_dict = job.__dict__
print(job_dict)
job_dict["CarPartsList"] = [part.__dict__ for part in job.CarParts]
print(len(job_dict["CarPartsList"]))
for part in job_dict["CarPartsList"]:
if (part["ImageURL"] is None) or (part["ImageURL"] == ""):
part["image"] = ""
@@ -75,11 +74,11 @@ def get_all_maintenance_jobs(db: Session):
job_dict["FinishedBy"] = job.FinishedBy.__dict__
job_dict["Vehicle"] = job.Vehicle.__dict__
result.append(job_dict)
print("Returning...")
return maintenancejobs


def get_maintenance_job(maintenancejob_id: int, db: Session):
print("Getting maintenance job by id: " + str(maintenancejob_id))
maintenancejob = (
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":
res["FinishedBy"] = maintenancejob.FinishedBy.__dict__
res["Vehicle"] = maintenancejob.Vehicle.__dict__
print("DB Access complete")
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 = (
db.query(MaintenanceJob).filter(MaintenanceJob.Id == maintenancejob_id).first()
)
if maintenancejob is None:
return None
if (status == "Complete"):
if status == "Complete":
maintenancejob.MaintenanceWorker = worker_id
maintenancejob.Status = status
db.commit()
@@ -114,6 +122,3 @@ def change_maintenance_status(maintenancejob_id: int, status: str, worker_id: in
return maintenancejob
else:
return None


+ 0
- 3
app/db/repository/report.py View File

@@ -128,8 +128,6 @@ def get_pdf(driver_id: int, db: Session):
content.append(title)
content.append(Paragraph("<br/>", title_style))

print(report_data["Driver"])

# Add detailed information about the driver
driver_info = [
["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))

vehicle = report_data["Driver"]["AssignedVehicle"].__dict__
print(vehicle)
if (
vehicle["CurrentLocation"] is None
or vehicle["CurrentLocation"] == ""


+ 11
- 0
app/db/repository/user.py View File

@@ -9,6 +9,7 @@ from db.models.drivetask import DriveTask


def create_new_user(user: UserCreate, db: Session):
print("Creating new user" + str(user))
if get_user_by_email(user.Email, db):
return "userExists"
user_object = User(
@@ -29,6 +30,7 @@ def create_new_user(user: UserCreate, db: Session):


def create_new_driver(driver: DriverCreate, db: Session):
print("Creating new driver" + str(driver))
if get_user_by_email(driver.Email, db):
return "userExists"
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):
print("Retrieving user by id: " + str(user_id))
user = db.query(User).filter(User.Id == user_id).first()
if not user:
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):
print("Retrieving user by email: " + str(email))
user = db.query(User).filter(User.Email == email).first()
return user


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()
return user


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()
if not driver:
return False
@@ -78,6 +84,7 @@ def verify_driver_exists(driver_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()
if not driver:
return False
@@ -85,6 +92,7 @@ def get_car_driver(vehicle_id: int, db: Session):


def list_users(db: Session, role: str = "Any"):
print("Listing users")
users = db.query(User).filter((User.Role == role) | (role == "Any")).all()
return users

@@ -92,6 +100,7 @@ def list_users(db: Session, role: str = "Any"):
def get_users_by_name(
db: Session, name: str = "", role: str = None, page: int = 1, per_page: int = 20
):
print("Listing users by name")
if role == "Admin":
return 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):
print("Replacing user data" + str(user_data) + " for user id: " + str(user_id))
user = db.query(User).filter(User.Id == user_id).first()
if not user:
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):
print("Deleting user by id: " + str(id))
user = db.query(User).filter(User.Id == id).first()
if not user:
return "userNotFound"


+ 7
- 2
app/db/repository/vehicle.py View File

@@ -6,6 +6,7 @@ from db.repository.user import get_car_driver


def create_new_vehicle(vehicle: CreateVehicle, db: Session):
print("Creating new vehicle" + str(vehicle))
vehicle_object = Vehicle(
**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):
print("Updating vehicle geolocation" + str(location))
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == vehicle_id)
vehicle_object = vehicle_db.first()
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):
print("Assigning vehicle " + str(vehicle_id) + " to driver " + str(driver_id))
if driver_id != None:
driver = (
db.query(User)
.filter((User.Id == driver_id) & (User.Role == "Driver"))
.first()
)
print(driver)
vehicle = db.query(Vehicle).filter(Vehicle.Id == vehicle_id).first()
if not vehicle:
return "novehicle"
@@ -59,6 +61,7 @@ def assign_vehicle_driver(vehicle_id: int, driver_id: int, db: Session):


def list_vehicles(db: Session):
print("Listing vehicles")
vehicles = db.query(Vehicle).all()
# assign AssignedDriver to all vehicles based on their drivers
for vehicle in vehicles:
@@ -71,6 +74,7 @@ def list_vehicles(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()
if not vehicle:
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):
print("Replacing vehicle data for vehicle " + str(id) + " with " + str(vehicle))
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id)
vehicle_object = vehicle_db.first()
if not vehicle_object:
@@ -100,7 +105,6 @@ def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session):
# return "driverNotFound"
vehicle_object.Capacity = vehicle.Capacity
vehicle_object.Year = vehicle.Year
print(vehicle_object)
db.add(vehicle_object)
db.commit()
# 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):
print("Deleting vehicle data for vehicle " + str(id))
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id)
vehicle_object = vehicle_db.first()
if not vehicle_object:


Loading…
Cancel
Save