|
|
@@ -1,5 +1,5 @@ |
|
|
|
from sqlalchemy.orm import Session |
|
|
|
from schemas.vehicle import CreateVehicle, OutputVehicle |
|
|
|
from schemas.vehicle import CreateVehicle, OutputVehicle, UpdateVehicle |
|
|
|
from db.models.vehicle import Vehicle |
|
|
|
from db.repository.user import verify_driver_exists |
|
|
|
|
|
|
@@ -45,3 +45,23 @@ def list_vehicles(db: Session): |
|
|
|
def get_vehicle_by_id(vehicle_id: int, db: Session): |
|
|
|
vehicle = db.query(Vehicle).filter(Vehicle.Id == vehicle_id).first() |
|
|
|
return vehicle |
|
|
|
|
|
|
|
|
|
|
|
def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session): |
|
|
|
vehicle_db = db.query(Vehicle).filter(Vehicle.Id == id) |
|
|
|
vehicle_object = vehicle_db.first() |
|
|
|
if not vehicle_object: |
|
|
|
return "vehiclenotfound" |
|
|
|
vehicle_object.AssignedDriverIds = vehicle.AssignedDriverIds |
|
|
|
vehicle_object.CurrentLocation = vehicle.CurrentLocation |
|
|
|
vehicle_object.Fuel = vehicle.Fuel |
|
|
|
vehicle_object.LicensePlate = vehicle.LicensePlate |
|
|
|
vehicle_object.MaintenanceNotes = vehicle.MaintenanceNotes |
|
|
|
vehicle_object.Mileage = vehicle.Mileage |
|
|
|
vehicle_object.Model = vehicle.Model |
|
|
|
vehicle_object.Type = vehicle.Type |
|
|
|
vehicle_object.Year = vehicle.Year |
|
|
|
print(vehicle_object) |
|
|
|
db.add(vehicle_object) |
|
|
|
db.commit() |
|
|
|
return vehicle_object |