fix: Cleaning up the code base

This commit is contained in:
Lino Mallevaey
2025-08-18 21:07:24 +02:00
parent 49bcb38261
commit 6f4dc2244a
6 changed files with 25 additions and 43 deletions

View File

@@ -6,12 +6,12 @@ ENV=dev # dev, prod
# =========================
# DATABASE CONFIGURATION
# =========================
# URL de connexion SQLAlchemy
# Pour PyMySQL (synchrone)
DATABASE_URL=mysql+pymysql://user:password@localhost:3306/db_name
# Pour aiomysql (async)
# DATABASE_URL=mysql+aiomysql://user:password@localhost:3306/mokpyo
# connexion SQLAlchemy
DATABASE_HOST=localhost
DATABASE_PORT=3306
DATABASE_USER=user
DATABASE_PASSWORD=password
DATABASE_NAME=mokpyo
# Pooling / Options SQLAlchemy (optionnel)
# MAX_CONNECTIONS=10

3
.gitignore vendored
View File

@@ -179,3 +179,6 @@ cython_debug/
# git
.git/
# custom tests files
*.test.py

View File

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

View File

@@ -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)
@@ -71,5 +80,3 @@ class Settings(BaseSettings):
# Instance globale
settings = Settings()
print("test")

View File

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

View File

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