Bladeren bron

Bugfixes, CORS in dev

main
Madiwka 1 jaar geleden
bovenliggende
commit
85ac40bfd7
5 gewijzigde bestanden met toevoegingen van 15 en 3 verwijderingen
  1. +8
    -0
      app/apis/v1/route_user.py
  2. +1
    -1
      app/core/config.py
  3. +1
    -1
      app/db/repository/drivetask.py
  4. +4
    -0
      app/db/repository/user.py
  5. +1
    -1
      app/main.py

+ 8
- 0
app/apis/v1/route_user.py Bestand weergeven

@@ -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




+ 1
- 1
app/core/config.py Bestand weergeven

@@ -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}"


+ 1
- 1
app/db/repository/drivetask.py Bestand weergeven

@@ -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"


+ 4
- 0
app/db/repository/user.py Bestand weergeven

@@ -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,


+ 1
- 1
app/main.py Bestand weergeven

@@ -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("/")


Laden…
Annuleren
Opslaan