fix: Cleaning up the code base
This commit is contained in:
@@ -13,32 +13,3 @@ router = APIRouter()
|
||||
@router.get("/ping", tags=["Test"])
|
||||
def ping():
|
||||
return {"message": "pong"}
|
||||
|
||||
# =========================
|
||||
# EXEMPLE UTILISATEUR
|
||||
# =========================
|
||||
@router.get("/me", tags=["User"])
|
||||
def read_current_user(current_user: dict = Depends(get_current_user)):
|
||||
"""
|
||||
Retourne les infos de l'utilisateur connecté
|
||||
"""
|
||||
return {"user": current_user}
|
||||
|
||||
# =========================
|
||||
# EXEMPLE AUTH
|
||||
# =========================
|
||||
@router.post("/hash-password", tags=["Auth"])
|
||||
def test_hash_password(password: str):
|
||||
"""
|
||||
Exemple simple pour hasher un mot de passe
|
||||
"""
|
||||
hashed = hash_password(password)
|
||||
return {"password": password, "hashed": hashed}
|
||||
|
||||
@router.post("/verify-password", tags=["Auth"])
|
||||
def test_verify_password(password: str, hashed: str):
|
||||
"""
|
||||
Vérifie qu'un mot de passe correspond à un hash
|
||||
"""
|
||||
valid = verify_password(password, hashed)
|
||||
return {"valid": valid}
|
||||
|
||||
@@ -10,7 +10,12 @@ class Settings(BaseSettings):
|
||||
# =========================
|
||||
# DATABASE
|
||||
# =========================
|
||||
DATABASE_URL: str
|
||||
DATABASE_HOST: str
|
||||
DATABASE_PORT: int
|
||||
DATABASE_USER: str
|
||||
DATABASE_PASSWORD: str
|
||||
DATABASE_NAME: str
|
||||
DATABASE_DRIVER: str
|
||||
|
||||
# =========================
|
||||
# FASTAPI
|
||||
@@ -61,6 +66,10 @@ class Settings(BaseSettings):
|
||||
# =========================
|
||||
ORJSON_STRICT: bool = True
|
||||
|
||||
@property
|
||||
def database_url(self) -> str:
|
||||
return f"mysql+<driver>://{self.DATABASE_USER}:{self.DATABASE_PASSWORD}@{self.DATABASE_HOST}:{self.DATABASE_PORT}/{self.DATABASE_NAME}"
|
||||
|
||||
@property
|
||||
def access_token_expire(self) -> timedelta:
|
||||
return timedelta(minutes=self.ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||
@@ -70,6 +79,4 @@ class Settings(BaseSettings):
|
||||
env_file_encoding = "utf-8"
|
||||
|
||||
# Instance globale
|
||||
settings = Settings()
|
||||
|
||||
print("test")
|
||||
settings = Settings()
|
||||
@@ -8,3 +8,4 @@ __version__ = "1.0.0"
|
||||
|
||||
from .engine import engine, async_engine
|
||||
from .session import SessionLocal, AsyncSessionLocal, get_db, get_async_db
|
||||
from .models import Base
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncEngine
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, Engine
|
||||
from app.core.config import settings
|
||||
|
||||
# =========================
|
||||
# SYNCHRONOUS ENGINE
|
||||
# =========================
|
||||
# Pour opérations sync classiques
|
||||
engine = create_engine(
|
||||
settings.DATABASE_URL.replace("+aiomysql", ""), # remove async part if present
|
||||
engine: Engine = create_engine(
|
||||
settings.database_url.replace('<driver>', "pymysql"),
|
||||
echo=settings.DEBUG,
|
||||
future=True
|
||||
)
|
||||
@@ -17,7 +17,7 @@ engine = create_engine(
|
||||
# =========================
|
||||
# Pour opérations async avec async SQLAlchemy
|
||||
async_engine: AsyncEngine = create_async_engine(
|
||||
settings.DATABASE_URL if "+aiomysql" in settings.DATABASE_URL else settings.DATABASE_URL.replace("mysql+pymysql", "mysql+aiomysql"),
|
||||
settings.database_url.replace('<driver>', "aiomysql"),
|
||||
echo=settings.DEBUG,
|
||||
future=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user