@@ -0,0 +1,13 @@ | |||||
FROM python:3.11-slim | |||||
WORKDIR /app | |||||
COPY ./requirements.txt . | |||||
RUN pip install --no-cache-dir -r requirements.txt | |||||
ENV PYTHONPATH "${PYTHONPATH}:/app/core:/:/app:/app/app/core:/app/app" | |||||
COPY . . | |||||
EXPOSE 2764 | |||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "2764"] | |||||
@@ -4,6 +4,7 @@ from sqlalchemy.orm import Session | |||||
from fastapi import Depends | from fastapi import Depends | ||||
from typing import List, Annotated | from typing import List, Annotated | ||||
from apis.v1.route_auth import get_current_user | from apis.v1.route_auth import get_current_user | ||||
from core.config import Settings | |||||
from db.models.user import User | from db.models.user import User | ||||
from schemas.user import UserCreate, ShowUser, ShowDriver, DriverCreate | from schemas.user import UserCreate, ShowUser, ShowDriver, DriverCreate | ||||
from db.session import get_db | from db.session import get_db | ||||
@@ -26,6 +27,11 @@ def create_user( | |||||
db: Session = Depends(get_db), | db: Session = Depends(get_db), | ||||
current_user: User = Depends(get_current_user), | current_user: User = Depends(get_current_user), | ||||
): | ): | ||||
if user.Role not in Settings.ALLOWED_ROLES: | |||||
raise HTTPException( | |||||
status_code=400, | |||||
detail=f"Status {status} is not allowed. Allowed status are {settings.ALLOWED_TASK_STATUS}", | |||||
) | |||||
if current_user.Role != "Admin": | if current_user.Role != "Admin": | ||||
raise HTTPException( | raise HTTPException( | ||||
status_code=403, detail="You are not authorized to perform this action" | status_code=403, detail="You are not authorized to perform this action" | ||||
@@ -11,6 +11,7 @@ class Settings: | |||||
SECRET_KEY: str = "tH357aC6oA7ofCaN3yTffYkRh" | SECRET_KEY: str = "tH357aC6oA7ofCaN3yTffYkRh" | ||||
ALGORITHM: str = "HS256" | ALGORITHM: str = "HS256" | ||||
ALLOWED_TASK_STATUS: list = ["Pending", "In Progress", "Completed", "Cancelled"] | ALLOWED_TASK_STATUS: list = ["Pending", "In Progress", "Completed", "Cancelled"] | ||||
ALLOWED_ROLES: list = ["Admin", "Driver", "Maintenance", "Fueling"] | |||||
settings = Settings() | settings = Settings() | ||||
@@ -1,4 +1,4 @@ | |||||
from sqlalchemy import Column, Integer, String, ForeignKey, LargeBinary | |||||
from sqlalchemy import Column, Float, Integer, String, ForeignKey, LargeBinary | |||||
from sqlalchemy.orm import relationship | from sqlalchemy.orm import relationship | ||||
from db.base import Base | from db.base import Base | ||||
@@ -12,4 +12,4 @@ class CarPart(Base): | |||||
Number = Column(String, nullable=False) | Number = Column(String, nullable=False) | ||||
Condition = Column(String, nullable=False) | Condition = Column(String, nullable=False) | ||||
ImageURL = Column(LargeBinary, nullable=False) | ImageURL = Column(LargeBinary, nullable=False) | ||||
Cost = Column(Integer, nullable=False) | |||||
Cost = Column(Float, nullable=False) |
@@ -1,4 +1,4 @@ | |||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, LargeBinary | |||||
from sqlalchemy import Column, Float, Integer, String, ForeignKey, DateTime, LargeBinary | |||||
from sqlalchemy.orm import relationship | from sqlalchemy.orm import relationship | ||||
from db.base import Base | from db.base import Base | ||||
@@ -11,7 +11,7 @@ class FuelingTask(Base): | |||||
Date = Column(DateTime, nullable=False) | Date = Column(DateTime, nullable=False) | ||||
Description = Column(String, nullable=True) | Description = Column(String, nullable=True) | ||||
Cost = Column(Integer, nullable=False) | Cost = Column(Integer, nullable=False) | ||||
FuelRefilled = Column(Integer, nullable=False) | |||||
FuelRefilled = Column(Float, nullable=False) | |||||
GasStationName = Column(String, nullable=False) | GasStationName = Column(String, nullable=False) | ||||
ImageBefore = Column(LargeBinary, nullable=False) | ImageBefore = Column(LargeBinary, nullable=False) | ||||
ImageAfter = Column(LargeBinary, nullable=False) | ImageAfter = Column(LargeBinary, nullable=False) | ||||
@@ -1,6 +1,7 @@ | |||||
# Postgres table model for vehicles | # Postgres table model for vehicles | ||||
from sqlalchemy import ( | from sqlalchemy import ( | ||||
Column, | Column, | ||||
Float, | |||||
Integer, | Integer, | ||||
String, | String, | ||||
ARRAY, | ARRAY, | ||||
@@ -16,8 +17,8 @@ class Vehicle(Base): | |||||
LicensePlate = Column(String, nullable=False) | LicensePlate = Column(String, nullable=False) | ||||
Type = 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) | |||||
Mileage = Column(Integer, nullable=False) | |||||
Fuel = Column(Float, nullable=False) | |||||
Mileage = Column(Float, nullable=False) | |||||
Status = Column(String, nullable=False) | Status = Column(String, nullable=False) | ||||
Capacity = Column(Integer, nullable=False) | Capacity = Column(Integer, nullable=False) | ||||
DriverHistory = Column(ARRAY(Integer), nullable=True) | DriverHistory = Column(ARRAY(Integer), nullable=True) | ||||
@@ -1 +0,0 @@ | |||||
/usr/local/bin/python3.10/usr/local/bin/python |
@@ -0,0 +1,9 @@ | |||||
fastapi[all] | |||||
pydantic | |||||
sqlalchemy | |||||
psycopg2-binary | |||||
alembic==1.12.0 | |||||
passlib | |||||
python-jose==3.3.0 | |||||
python-multipart==0.0.6 | |||||
requests |
@@ -13,6 +13,7 @@ class UserCreate(BaseModel): | |||||
GovernmentId: str = Field(...) | GovernmentId: str = Field(...) | ||||
Address: str = Field(...) | Address: str = Field(...) | ||||
Email: EmailStr = Field(...) | Email: EmailStr = Field(...) | ||||
Role: str = Field(...) | |||||
class DriverCreate(UserCreate): | class DriverCreate(UserCreate): | ||||
@@ -0,0 +1 @@ | |||||
uvicorn main:app --host 0.0.0.0 --port 2764 |
@@ -0,0 +1,25 @@ | |||||
version: "3.11" | |||||
services: | |||||
backend: | |||||
build: app | |||||
ports: | |||||
- "8000:2764" | |||||
depends_on: | |||||
- db | |||||
db: | |||||
image: "postgres" | |||||
restart: always | |||||
environment: | |||||
POSTGRES_USER: VMSBase | |||||
POSTGRES_PASSWORD: VMSBasePass | |||||
POSTGRES_DB: VMSData | |||||
POSTGRES_PORT: 5432 | |||||
expose: | |||||
- "5432" | |||||
networks: | |||||
practice: |
@@ -1,8 +1,9 @@ | |||||
fastapi[all] | fastapi[all] | ||||
pydantic | pydantic | ||||
sqlalchemy | sqlalchemy | ||||
psycopg2 | |||||
psycopg2-binary | |||||
alembic==1.12.0 | alembic==1.12.0 | ||||
passlib | passlib | ||||
python-jose==3.3.0 | python-jose==3.3.0 | ||||
python-multipart==0.0.6 | |||||
python-multipart==0.0.6 | |||||
requests |