@@ -19,12 +19,33 @@ async def create_vehicle(vehicle: CreateVehicle, db: Session = Depends(get_db)): | |||||
return vehicle | return vehicle | ||||
@router.get( | |||||
"/assign/{vehicle_id}/{driver_id}", | |||||
# @router.get( | |||||
# "/assign/{vehicle_id}/{driver_id}", | |||||
# response_model=OutputVehicle, | |||||
# status_code=status.HTTP_200_OK, | |||||
# ) | |||||
# async def assign_drver(vehicle_id: int, driver_id: int, db: Session = Depends(get_db)): | |||||
# vehicle = assign_vehicle_driver(vehicle_id=vehicle_id, driver_id=driver_id, db=db) | |||||
# if vehicle == "nodriver": | |||||
# raise HTTPException( | |||||
# status_code=404, detail=f"Driver with id {driver_id} not found" | |||||
# ) | |||||
# if vehicle == "novehicle": | |||||
# raise HTTPException( | |||||
# status_code=404, detail=f"Vehicle with id {vehicle_id} not found" | |||||
# ) | |||||
# if vehicle == "alreadyassigned": | |||||
# raise HTTPException( | |||||
# status_code=400, | |||||
# detail=f"Driver with id {driver_id} is already assigned to vehicle with id {vehicle_id}", | |||||
# ) | |||||
# return vehicle | |||||
@router.patch( | |||||
"/{vehicle_id}/driver/{driver_id}", | |||||
response_model=OutputVehicle, | response_model=OutputVehicle, | ||||
status_code=status.HTTP_200_OK, | status_code=status.HTTP_200_OK, | ||||
) | ) | ||||
async def assign_drver(vehicle_id: int, driver_id: int, db: Session = Depends(get_db)): | |||||
async def assign_driver(vehicle_id: int, driver_id: int, db: Session = Depends(get_db)): | |||||
vehicle = assign_vehicle_driver(vehicle_id=vehicle_id, driver_id=driver_id, db=db) | vehicle = assign_vehicle_driver(vehicle_id=vehicle_id, driver_id=driver_id, db=db) | ||||
if vehicle == "nodriver": | if vehicle == "nodriver": | ||||
raise HTTPException( | raise HTTPException( | ||||
@@ -7,20 +7,20 @@ from core.hashing import Hasher | |||||
def create_new_user(user: UserCreate, db: Session): | def create_new_user(user: UserCreate, db: Session): | ||||
user = User( | |||||
Email=user.email, | |||||
Name=user.name, | |||||
MiddleName=user.middlename, | |||||
LastName=user.lastname, | |||||
BirthDate=user.birthdate, | |||||
ContactNumber=user.phone, | |||||
Role=user.role, | |||||
HashedPassword=Hasher.get_password_hash(user.password), | |||||
user_object = User( | |||||
Email=user.Email, | |||||
Name=user.Name, | |||||
MiddleName=user.MiddleName, | |||||
LastName=user.LastName, | |||||
BirthDate=user.BirthDate, | |||||
ContactNumber=user.ContactNumber, | |||||
Role=user.Role, | |||||
HashedPassword=Hasher.get_password_hash(user.Password), | |||||
) | ) | ||||
db.add(user) | |||||
db.add(user_object) | |||||
db.commit() | db.commit() | ||||
db.refresh(user) | |||||
return user | |||||
db.refresh(user_object) | |||||
return user_object | |||||
def verify_driver_exists(driver_id: int, db: Session): | def verify_driver_exists(driver_id: int, db: Session): | ||||
@@ -5,20 +5,16 @@ from db.repository.user import verify_driver_exists | |||||
def create_new_vehicle(vehicle: CreateVehicle, db: Session): | def create_new_vehicle(vehicle: CreateVehicle, db: Session): | ||||
vehicle = Vehicle( | |||||
Model=vehicle.model, | |||||
Year=vehicle.year, | |||||
LicensePlate=vehicle.license_plate, | |||||
Type=vehicle.type, | |||||
Mileage=vehicle.mileage, | |||||
vehicle_object = Vehicle( | |||||
**vehicle.model_dump(), | |||||
Fuel=0, | |||||
AssignedDriverIds=[], | AssignedDriverIds=[], | ||||
CurrentLocation=[], | CurrentLocation=[], | ||||
Fuel=0, | |||||
MaintenanceNotes=[], | |||||
MaintenanceNotes=[] | |||||
) | ) | ||||
db.add(vehicle) | |||||
db.add(vehicle_object) | |||||
db.commit() | db.commit() | ||||
db.refresh(vehicle) | |||||
db.refresh(vehicle_object) | |||||
return vehicle | return vehicle | ||||
@@ -5,15 +5,15 @@ from pydantic import BaseModel, EmailStr, Field | |||||
class UserCreate(BaseModel): | class UserCreate(BaseModel): | ||||
email: EmailStr | |||||
password: str = Field(..., min_length=7, max_length=20) | |||||
name: str = Field(..., min_length=3, max_length=50) | |||||
middlename: str = Field(None, min_length=3, max_length=50) | |||||
lastname: str = Field(..., min_length=3, max_length=50) | |||||
phone: str = Field(..., min_length=12, max_length=12) | |||||
birthdate: datetime = Field(...) | |||||
email: EmailStr = Field(...) | |||||
role: str = Field(..., min_length=3, max_length=50) | |||||
Email: EmailStr | |||||
Password: str = Field(..., min_length=7, max_length=20) | |||||
Name: str = Field(..., min_length=3, max_length=50) | |||||
MiddleName: str = Field(None, min_length=3, max_length=50) | |||||
LastName: str = Field(..., min_length=3, max_length=50) | |||||
ContactNumber: str = Field(..., min_length=12, max_length=12) | |||||
BirthDate: datetime = Field(...) | |||||
Email: EmailStr = Field(...) | |||||
Role: str = Field(..., min_length=3, max_length=50) | |||||
class ShowUser(BaseModel): | class ShowUser(BaseModel): | ||||
@@ -4,15 +4,16 @@ from datetime import datetime | |||||
class CreateVehicle(BaseModel): | class CreateVehicle(BaseModel): | ||||
id: int | |||||
model: str | |||||
year: int | |||||
license_plate: str | |||||
type: str | |||||
mileage: int | |||||
Id: int | |||||
Model: str | |||||
Year: int | |||||
LicensePlate: str | |||||
Type: str | |||||
Mileage: int | |||||
class OutputVehicle(BaseModel): | class OutputVehicle(BaseModel): | ||||
Id: int | |||||
Model: str | Model: str | ||||
Year: int | Year: int | ||||
LicensePlate: str | LicensePlate: str | ||||