diff --git a/auth/dependencies.py b/auth/dependencies.py index 4369645..ec55db5 100644 --- a/auth/dependencies.py +++ b/auth/dependencies.py @@ -2,7 +2,7 @@ from fastapi import Depends, status, Request from fastapi.security import OAuth2PasswordBearer import jwt # auth/dependencies.py - +# @/auth/dependencies.py from sqlalchemy.orm import Session from database import get_db from models.user import User diff --git a/config.py b/config.py index c647a40..bd70d96 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,4 @@ +# @/config.py from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): diff --git a/crud/user.py b/crud/user.py index 7c96b89..a84b78c 100644 --- a/crud/user.py +++ b/crud/user.py @@ -1,4 +1,4 @@ -# crud/user.py +# @/crud/user.py from sqlalchemy import select, exists, func from sqlalchemy.orm import Session from sqlalchemy.exc import IntegrityError diff --git a/exceptions.py b/exceptions.py index 11409a1..42622ae 100644 --- a/exceptions.py +++ b/exceptions.py @@ -1,3 +1,4 @@ +# @/exeptions.py from typing import Any diff --git a/main.py b/main.py index cf7f513..9451a58 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,18 @@ +# @/main.py from fastapi import FastAPI, Request, status from fastapi.responses import JSONResponse from fastapi.templating import Jinja2Templates -from exceptions import UserNotFoundError, UserAlreadyExistsError, UnauthorizedError, ForbiddenError, ValidationError + +from exceptions import UserNotFoundError, UserAlreadyExistsError, UnauthorizedError, ForbiddenError, ValidationError #Errors import models #Database from routers import api_router #API + app = FastAPI(title="Tandur API") app.include_router(api_router) templates = Jinja2Templates(directory="templates") + ######### ERROR handling ######### # 1. Globale Regel für 404 diff --git a/routers/__init__.py b/routers/__init__.py index b7551a2..6b211b1 100644 --- a/routers/__init__.py +++ b/routers/__init__.py @@ -1,3 +1,4 @@ +# @/routers/__init__.py from fastapi import APIRouter from .users import router as users_router diff --git a/routers/auth.py b/routers/auth.py index 4a56ea3..d270d64 100644 --- a/routers/auth.py +++ b/routers/auth.py @@ -1,4 +1,4 @@ -# routers/auth.py +# @/routers/auth.py from fastapi import APIRouter, Depends, status, Response from fastapi.security import OAuth2PasswordRequestForm from sqlalchemy.orm import Session @@ -6,7 +6,7 @@ from sqlalchemy.orm import Session from database import get_db from schemas.auth import LoginRequest from schemas.user import UserResponse -#from exceptions import UserAlreadyExistsError, UserNotFoundError +from exceptions import UnauthorizedError from crud.user import get_user_by_email from auth.security import verify_password, create_access_token diff --git a/routers/users.py b/routers/users.py index 309bd37..78e0c40 100644 --- a/routers/users.py +++ b/routers/users.py @@ -1,4 +1,4 @@ -# routers/users.py +# @/routers/users.py from fastapi import APIRouter, Depends, HTTPException, status from sqlalchemy.orm import Session diff --git a/schemas/auth.py b/schemas/auth.py index 303731f..500ad4f 100644 --- a/schemas/auth.py +++ b/schemas/auth.py @@ -1,4 +1,4 @@ -# /schemas/auth.py +# @/schemas/auth.py from pydantic import BaseModel diff --git a/schemas/user.py b/schemas/user.py index 30a6827..758a690 100644 --- a/schemas/user.py +++ b/schemas/user.py @@ -1,3 +1,4 @@ +# @/schemas/user.py from pydantic import BaseModel class UserCreate(BaseModel): diff --git a/test.py b/test.py index 0dcc6e8..2321cef 100644 --- a/test.py +++ b/test.py @@ -4,33 +4,14 @@ import models Base.metadata.create_all(bind=engine) # falls Tabelle noch nicht existiert -from crud.user import create_user, get_user_by_email, update_user, delete_user, verify_password +from crud.user import get_users, get_user_by_email, update_user, delete_user db = SessionLocal() # Erstellen -u = create_user(db, email="2test@example.com", password="test1234", role="admin") -print("Erstellt:", u.id, u.email, u.role) +u = get_users(db) +for user in u: + print(f"User: {user.email}, role: {user.role}, created_at: {user.created_at}") -# Lesen -found = get_user_by_email(db, "1test@example.com") -print(found) -print("Gefunden:", found.email if found else "nicht gefunden") - -# Passwort prüfen -print("Passwort korrekt:", verify_password("test1234", found.password)) -print("Falsches Passwort:", verify_password("falsch", found.password)) - -# Updaten -updated = update_user(db, u.id, email="neu@example.com") -print("Aktualisiert:", updated.email) - -# Löschen -success = delete_user(db, u.id) -print("Gelöscht:", success) - -# Prüfen, ob wirklich weg -gone = get_user_by_email(db, "neu@example.com") -print("Nach Löschen noch da?:", gone) db.close()