diff --git a/app/apis/v1/route_user.py b/app/apis/v1/route_user.py index f8920d1..4db439e 100644 --- a/app/apis/v1/route_user.py +++ b/app/apis/v1/route_user.py @@ -50,6 +50,10 @@ def create_user( # if current_user.Role != "Admin": # raise HTTPException(status_code=403, detail="You are not authorized to perform this action") 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 @@ -64,6 +68,10 @@ def create_driver( status_code=403, detail="You are not authorized to perform this action" ) 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 diff --git a/app/core/config.py b/app/core/config.py index 46d5128..beff9c0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -3,7 +3,7 @@ class Settings: PROJECT_VERSION: str = "1.0.0" POSTGRES_USER: str = "VMSBase" POSTGRES_PASSWORD = "VMSBasePass" - POSTGRES_SERVER: str = "db" + POSTGRES_SERVER: str = "localhost" POSTGRES_PORT: str = "5432" POSTGRES_DB: str = "VMSData" DATABASE_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}" diff --git a/app/db/repository/drivetask.py b/app/db/repository/drivetask.py index f33ae20..bfde757 100644 --- a/app/db/repository/drivetask.py +++ b/app/db/repository/drivetask.py @@ -8,7 +8,7 @@ from db.repository.user import get_user_by_id def create_new_task(task: CreateTask, db: Session): driver = get_user_by_id(task.DriverId, "Driver", db) - if driver is None: + if not driver: return "notdriver" elif driver.Role != "Driver": return "notdriver" diff --git a/app/db/repository/user.py b/app/db/repository/user.py index 78d8878..cdccfb2 100644 --- a/app/db/repository/user.py +++ b/app/db/repository/user.py @@ -9,6 +9,8 @@ from db.models.drivetask import DriveTask def create_new_user(user: UserCreate, db: Session): + if get_user_by_email(user.Email, db): + return "userExists" user_object = User( Email=user.Email, Name=user.Name, @@ -27,6 +29,8 @@ def create_new_user(user: UserCreate, db: Session): def create_new_driver(driver: DriverCreate, db: Session): + if get_user_by_email(driver.Email, db): + return "userExists" driver_object = User( Email=driver.Email, Name=driver.Name, diff --git a/app/main.py b/app/main.py index a98127d..cc56a50 100644 --- a/app/main.py +++ b/app/main.py @@ -22,7 +22,7 @@ def startup(): # start the project, and create the tables origins = ["*"] 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 @app.get("/")