|
|
@@ -1,9 +1,9 @@ |
|
|
|
from fastapi import APIRouter, status, HTTPException |
|
|
|
from sqlalchemy.orm import Session |
|
|
|
from fastapi import Depends |
|
|
|
from typing import List |
|
|
|
from typing import Annotated, List |
|
|
|
from db.session import get_db |
|
|
|
from schemas.vehicle import OutputVehicle, CreateVehicle, UpdateVehicle |
|
|
|
from schemas.vehicle import OutputVehicle, CreateVehicle, UpdateVehicle, VehicleLocation |
|
|
|
from db.repository.vehicle import ( |
|
|
|
create_new_vehicle, |
|
|
|
assign_vehicle_driver, |
|
|
@@ -11,6 +11,7 @@ from db.repository.vehicle import ( |
|
|
|
get_vehicle_by_id, |
|
|
|
replace_vehicle_data, |
|
|
|
delete_vehicle_data, |
|
|
|
update_vehicle_location, |
|
|
|
) |
|
|
|
from db.models.user import User |
|
|
|
from apis.v1.route_auth import get_current_user |
|
|
@@ -24,6 +25,7 @@ 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" |
|
|
@@ -138,3 +140,23 @@ def delete_vehicle( |
|
|
|
if result == "vehicleNotFound": |
|
|
|
raise HTTPException(status_code=404, detail="Vehicle not found") |
|
|
|
return {"msg": "Vehicle deleted successfully"} |
|
|
|
|
|
|
|
|
|
|
|
@router.post("/{vehicle_id}/location", status_code=status.HTTP_200_OK) |
|
|
|
async def update_vehicle_location( |
|
|
|
vehicle_id: int, |
|
|
|
location: VehicleLocation, |
|
|
|
current_user: User = Depends(get_current_user), |
|
|
|
db: Session = Depends(get_db), |
|
|
|
): |
|
|
|
print(current_user) |
|
|
|
print(current_user.Name) |
|
|
|
if current_user.Role != "Driver": |
|
|
|
raise HTTPException(status_code=403, detail="You are not authorized to perform this action") |
|
|
|
if current_user.AssignedVehicle != vehicle_id: |
|
|
|
raise HTTPException(status_code=403, detail="You are not the correct car driver") |
|
|
|
print("FUNNY") |
|
|
|
vehicle = update_vehicle_location(vehicle_id = vehicle_id, location=location, db=db) |
|
|
|
if vehicle == "vehiclenotfound": |
|
|
|
raise HTTPException(status_code=404, detail="Vehicle not found") |
|
|
|
return vehicle |