Browse Source

Added improved VMS structures

main
Madiwka3 1 year ago
parent
commit
a3303e729f
7 changed files with 19 additions and 21 deletions
  1. +2
    -1
      app/core/config.py
  2. +3
    -2
      app/db/models/user.py
  3. +2
    -1
      app/db/models/vehicle.py
  4. +2
    -1
      app/db/repository/user.py
  5. +2
    -1
      app/db/repository/vehicle.py
  6. +4
    -3
      app/schemas/user.py
  7. +4
    -12
      app/schemas/vehicle.py

+ 2
- 1
app/core/config.py View File

@@ -29,7 +29,8 @@ def createAdminAcc():
LastName="Turgunov", LastName="Turgunov",
ContactNumber="+77071234567", ContactNumber="+77071234567",
Role="Admin", Role="Admin",
BirthDate="2000-01-01T00:00:00+06:00",
GovernmentId="123456789",
Address="Nazarbayev University",
) )
if db.query(User).filter(User.Email == user.Email).first(): if db.query(User).filter(User.Email == user.Email).first():
return False return False


+ 3
- 2
app/db/models/user.py View File

@@ -1,5 +1,5 @@
# PostgreSQL table model for users # PostgreSQL table model for users
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from db.base import Base from db.base import Base


@@ -9,7 +9,8 @@ class User(Base):
Name = Column(String, nullable=False) Name = Column(String, nullable=False)
MiddleName = Column(String, nullable=True) MiddleName = Column(String, nullable=True)
LastName = Column(String, nullable=False) LastName = Column(String, nullable=False)
BirthDate = Column(DateTime, nullable=False)
GovernmentId = Column(String, nullable=False)
Address = Column(String, nullable=False)
ContactNumber = Column(String, nullable=False) ContactNumber = Column(String, nullable=False)
Email = Column(String, nullable=False) Email = Column(String, nullable=False)
Role = Column(String, nullable=False) Role = Column(String, nullable=False)


+ 2
- 1
app/db/models/vehicle.py View File

@@ -14,10 +14,11 @@ class Vehicle(Base):
Model = Column(String, nullable=False) Model = Column(String, nullable=False)
Year = Column(Integer, nullable=False) Year = Column(Integer, nullable=False)
LicensePlate = Column(String, nullable=False) LicensePlate = Column(String, nullable=False)
Type = Column(String, nullable=False)
CurrentLocation = Column(ARRAY(String), nullable=True) CurrentLocation = Column(ARRAY(String), nullable=True)
Fuel = Column(Integer, nullable=False) Fuel = Column(Integer, nullable=False)
Mileage = Column(Integer, nullable=False) Mileage = Column(Integer, nullable=False)
Status = Column(String, nullable=False) Status = Column(String, nullable=False)
Capacity = Column(Integer, nullable=False) Capacity = Column(Integer, nullable=False)
MaintenanceNotes = Column(ARRAY(String), nullable=True)
DriverHistory = Column(ARRAY(Integer), nullable=True)
driver = relationship("User", back_populates="vehicle") driver = relationship("User", back_populates="vehicle")

+ 2
- 1
app/db/repository/user.py View File

@@ -12,7 +12,8 @@ def create_new_user(user: UserCreate, db: Session):
Name=user.Name, Name=user.Name,
MiddleName=user.MiddleName, MiddleName=user.MiddleName,
LastName=user.LastName, LastName=user.LastName,
BirthDate=user.BirthDate,
GovernmentId=user.GovernmentId,
Address=user.Address,
ContactNumber=user.ContactNumber, ContactNumber=user.ContactNumber,
Role=user.Role, Role=user.Role,
HashedPassword=Hasher.get_password_hash(user.Password), HashedPassword=Hasher.get_password_hash(user.Password),


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

@@ -78,7 +78,8 @@ def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session):
vehicle_object.CurrentLocation = vehicle.CurrentLocation vehicle_object.CurrentLocation = vehicle.CurrentLocation
vehicle_object.Fuel = vehicle.Fuel vehicle_object.Fuel = vehicle.Fuel
vehicle_object.LicensePlate = vehicle.LicensePlate vehicle_object.LicensePlate = vehicle.LicensePlate
vehicle_object.MaintenanceNotes = vehicle.MaintenanceNotes
vehicle_object.DriverHistory = vehicle.DriverHistory
vehicle_object.Type = vehicle.Type
vehicle_object.Mileage = vehicle.Mileage vehicle_object.Mileage = vehicle.Mileage
vehicle_object.Model = vehicle.Model vehicle_object.Model = vehicle.Model
vehicle_object.Status = vehicle.Status vehicle_object.Status = vehicle.Status


+ 4
- 3
app/schemas/user.py View File

@@ -1,6 +1,5 @@
# Purpose: User schema for pydantic (validation, inside-api usage) # Purpose: User schema for pydantic (validation, inside-api usage)


from datetime import datetime
from pydantic import BaseModel, EmailStr, Field from pydantic import BaseModel, EmailStr, Field




@@ -11,7 +10,8 @@ class UserCreate(BaseModel):
MiddleName: str = Field(None) MiddleName: str = Field(None)
LastName: str = Field(..., min_length=3, max_length=50) LastName: str = Field(..., min_length=3, max_length=50)
ContactNumber: str = Field(..., min_length=12, max_length=12) ContactNumber: str = Field(..., min_length=12, max_length=12)
BirthDate: datetime = Field(...)
GovernmentId: str = Field(...)
Address: str = Field(...)
Email: EmailStr = Field(...) Email: EmailStr = Field(...)
Role: str = Field(..., min_length=3, max_length=50) Role: str = Field(..., min_length=3, max_length=50)


@@ -22,7 +22,8 @@ class ShowUser(BaseModel):
MiddleName: str | None MiddleName: str | None
LastName: str LastName: str
ContactNumber: str ContactNumber: str
BirthDate: datetime
GovernmentId: str
Address: str
Email: EmailStr Email: EmailStr
Role: str Role: str
AssignedVehicle: int | None AssignedVehicle: int | None


+ 4
- 12
app/schemas/vehicle.py View File

@@ -18,23 +18,15 @@ class OutputVehicle(BaseModel):
Mileage: int Mileage: int
CurrentLocation: Optional[list[str]] = None CurrentLocation: Optional[list[str]] = None
Fuel: Optional[int] = 0 Fuel: Optional[int] = 0
MaintenanceNotes: Optional[list[str]] = None
Type: str
DriverHistory: Optional[list[int]] = None
AssignedDriver: Optional[int] = None AssignedDriver: Optional[int] = None
Capacity: int Capacity: int
Status: str Status: str




class UpdateVehicle(BaseModel):
Model: str
Year: int
LicensePlate: str
Capacity: int
Mileage: int
Status: str
CurrentLocation: Optional[list[str]] = None
Fuel: Optional[int] = 0
MaintenanceNotes: Optional[list[str]] = None
AssignedDriver: Optional[int] = None
class UpdateVehicle(OutputVehicle):
pass




class VehicleLocation(BaseModel): class VehicleLocation(BaseModel):


Loading…
Cancel
Save