Преглед изворни кода

Fixed Models to have similar names, fixed driver assignment to use Patch instead of Get

main
Madiwka3 пре 1 година
родитељ
комит
869794afda
5 измењених фајлова са 58 додато и 40 уклоњено
  1. +24
    -3
      app/apis/v1/route_vehicle.py
  2. +12
    -12
      app/db/repository/user.py
  3. +6
    -10
      app/db/repository/vehicle.py
  4. +9
    -9
      app/schemas/user.py
  5. +7
    -6
      app/schemas/vehicle.py

+ 24
- 3
app/apis/v1/route_vehicle.py Прегледај датотеку

@@ -19,12 +19,33 @@ async def create_vehicle(vehicle: CreateVehicle, db: Session = Depends(get_db)):
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,
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)
if vehicle == "nodriver":
raise HTTPException(


+ 12
- 12
app/db/repository/user.py Прегледај датотеку

@@ -7,20 +7,20 @@ from core.hashing import Hasher


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.refresh(user)
return user
db.refresh(user_object)
return user_object


def verify_driver_exists(driver_id: int, db: Session):


+ 6
- 10
app/db/repository/vehicle.py Прегледај датотеку

@@ -5,20 +5,16 @@ from db.repository.user import verify_driver_exists


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=[],
CurrentLocation=[],
Fuel=0,
MaintenanceNotes=[],
MaintenanceNotes=[]
)
db.add(vehicle)
db.add(vehicle_object)
db.commit()
db.refresh(vehicle)
db.refresh(vehicle_object)
return vehicle




+ 9
- 9
app/schemas/user.py Прегледај датотеку

@@ -5,15 +5,15 @@ from pydantic import BaseModel, EmailStr, Field


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):


+ 7
- 6
app/schemas/vehicle.py Прегледај датотеку

@@ -4,15 +4,16 @@ from datetime import datetime


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):
Id: int
Model: str
Year: int
LicensePlate: str


Loading…
Откажи
Сачувај