feat(core): Add database support to SeriesApp (Task 7)

- Added db_session parameter to SeriesApp.__init__()
- Added db_session property and set_db_session() method
- Added init_from_db_async() for async database initialization
- Pass db_session to SerieList and SerieScanner during construction
- Added get_series_app_with_db() dependency for FastAPI endpoints
- All 815 unit tests and 55 API tests pass
This commit is contained in:
2025-12-01 19:42:04 +01:00
parent 246782292f
commit cb014cf547
6 changed files with 291 additions and 330 deletions

View File

@@ -65,6 +65,10 @@ def get_series_app() -> SeriesApp:
Raises:
HTTPException: If SeriesApp is not initialized or anime directory
is not configured
Note:
This creates a SeriesApp without database support. For database-
backed storage, use get_series_app_with_db() instead.
"""
global _series_app
@@ -103,7 +107,6 @@ def reset_series_app() -> None:
_series_app = None
async def get_database_session() -> AsyncGenerator:
"""
Dependency to get database session.
@@ -166,6 +169,43 @@ async def get_optional_database_session() -> AsyncGenerator:
yield None
async def get_series_app_with_db(
db: AsyncSession = Depends(get_optional_database_session),
) -> SeriesApp:
"""
Dependency to get SeriesApp instance with database support.
This creates or returns a SeriesApp instance and injects the
database session for database-backed storage.
Args:
db: Optional database session from dependency injection
Returns:
SeriesApp: The main application instance with database support
Raises:
HTTPException: If SeriesApp is not initialized or anime directory
is not configured
Example:
@app.post("/api/anime/scan")
async def scan_anime(
series_app: SeriesApp = Depends(get_series_app_with_db)
):
# series_app has db_session configured
await series_app.serie_scanner.scan_async()
"""
# Get the base SeriesApp
app = get_series_app()
# Inject database session if available
if db:
app.set_db_session(db)
return app
def get_current_user(
credentials: Optional[HTTPAuthorizationCredentials] = Depends(
http_bearer_security