瀏覽代碼

Added improved VMS structures

main
Madiwka3 1 年之前
父節點
當前提交
a3303e729f
共有 7 個文件被更改,包括 19 次插入21 次删除
  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 查看文件

@@ -29,7 +29,8 @@ def createAdminAcc():
LastName="Turgunov",
ContactNumber="+77071234567",
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():
return False


+ 3
- 2
app/db/models/user.py 查看文件

@@ -1,5 +1,5 @@
# 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 db.base import Base

@@ -9,7 +9,8 @@ class User(Base):
Name = Column(String, nullable=False)
MiddleName = Column(String, nullable=True)
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)
Email = Column(String, nullable=False)
Role = Column(String, nullable=False)


+ 2
- 1
app/db/models/vehicle.py 查看文件

@@ -14,10 +14,11 @@ class Vehicle(Base):
Model = Column(String, nullable=False)
Year = Column(Integer, nullable=False)
LicensePlate = Column(String, nullable=False)
Type = Column(String, nullable=False)
CurrentLocation = Column(ARRAY(String), nullable=True)
Fuel = Column(Integer, nullable=False)
Mileage = Column(Integer, nullable=False)
Status = Column(String, 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")

+ 2
- 1
app/db/repository/user.py 查看文件

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


+ 2
- 1
app/db/repository/vehicle.py 查看文件

@@ -78,7 +78,8 @@ def replace_vehicle_data(id: int, vehicle: UpdateVehicle, db: Session):
vehicle_object.CurrentLocation = vehicle.CurrentLocation
vehicle_object.Fuel = vehicle.Fuel
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.Model = vehicle.Model
vehicle_object.Status = vehicle.Status


+ 4
- 3
app/schemas/user.py 查看文件

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

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


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

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


+ 4
- 12
app/schemas/vehicle.py 查看文件

@@ -18,23 +18,15 @@ class OutputVehicle(BaseModel):
Mileage: int
CurrentLocation: Optional[list[str]] = None
Fuel: Optional[int] = 0
MaintenanceNotes: Optional[list[str]] = None
Type: str
DriverHistory: Optional[list[int]] = None
AssignedDriver: Optional[int] = None
Capacity: int
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):


Loading…
取消
儲存