@@ -50,6 +50,10 @@ def create_user( | |||||
# if current_user.Role != "Admin": | # if current_user.Role != "Admin": | ||||
# raise HTTPException(status_code=403, detail="You are not authorized to perform this action") | # raise HTTPException(status_code=403, detail="You are not authorized to perform this action") | ||||
user = create_new_user(user=user, db=db) | user = create_new_user(user=user, db=db) | ||||
if user == "userExists": | |||||
raise HTTPException( | |||||
status_code=400, detail=f"User with this email already exists" | |||||
) | |||||
return user | return user | ||||
@@ -64,6 +68,10 @@ def create_driver( | |||||
status_code=403, detail="You are not authorized to perform this action" | status_code=403, detail="You are not authorized to perform this action" | ||||
) | ) | ||||
driver = create_new_driver(driver=driver, db=db) | driver = create_new_driver(driver=driver, db=db) | ||||
if driver == "userExists": | |||||
raise HTTPException( | |||||
status_code=400, detail=f"User with this email already exists" | |||||
) | |||||
return driver | return driver | ||||
@@ -3,7 +3,7 @@ class Settings: | |||||
PROJECT_VERSION: str = "1.0.0" | PROJECT_VERSION: str = "1.0.0" | ||||
POSTGRES_USER: str = "VMSBase" | POSTGRES_USER: str = "VMSBase" | ||||
POSTGRES_PASSWORD = "VMSBasePass" | POSTGRES_PASSWORD = "VMSBasePass" | ||||
POSTGRES_SERVER: str = "db" | |||||
POSTGRES_SERVER: str = "localhost" | |||||
POSTGRES_PORT: str = "5432" | POSTGRES_PORT: str = "5432" | ||||
POSTGRES_DB: str = "VMSData" | POSTGRES_DB: str = "VMSData" | ||||
DATABASE_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}" | DATABASE_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}" | ||||
@@ -8,7 +8,7 @@ from db.repository.user import get_user_by_id | |||||
def create_new_task(task: CreateTask, db: Session): | def create_new_task(task: CreateTask, db: Session): | ||||
driver = get_user_by_id(task.DriverId, "Driver", db) | driver = get_user_by_id(task.DriverId, "Driver", db) | ||||
if driver is None: | |||||
if not driver: | |||||
return "notdriver" | return "notdriver" | ||||
elif driver.Role != "Driver": | elif driver.Role != "Driver": | ||||
return "notdriver" | return "notdriver" | ||||
@@ -9,6 +9,8 @@ from db.models.drivetask import DriveTask | |||||
def create_new_user(user: UserCreate, db: Session): | def create_new_user(user: UserCreate, db: Session): | ||||
if get_user_by_email(user.Email, db): | |||||
return "userExists" | |||||
user_object = User( | user_object = User( | ||||
Email=user.Email, | Email=user.Email, | ||||
Name=user.Name, | Name=user.Name, | ||||
@@ -27,6 +29,8 @@ def create_new_user(user: UserCreate, db: Session): | |||||
def create_new_driver(driver: DriverCreate, db: Session): | def create_new_driver(driver: DriverCreate, db: Session): | ||||
if get_user_by_email(driver.Email, db): | |||||
return "userExists" | |||||
driver_object = User( | driver_object = User( | ||||
Email=driver.Email, | Email=driver.Email, | ||||
Name=driver.Name, | Name=driver.Name, | ||||
@@ -22,7 +22,7 @@ def startup(): # start the project, and create the tables | |||||
origins = ["*"] | origins = ["*"] | ||||
app = startup() | app = startup() | ||||
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], expose_headers=["*"]) | |||||
app.add_middleware(CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"]) | |||||
# Testing stuff | # Testing stuff | ||||
@app.get("/") | @app.get("/") | ||||