This commit is contained in:
maxDorninger
2025-03-28 19:21:11 +01:00
parent f13228dba9
commit 3a80f874f9
22 changed files with 299 additions and 271 deletions

View File

@@ -1,7 +1,13 @@
import logging
import sys
from contextlib import asynccontextmanager
from logging.config import dictConfig
import database
from auth.db import create_db_and_tables
from auth.schemas import UserCreate, UserRead, UserUpdate
from auth.users import bearer_auth_backend, fastapi_users
logging.basicConfig(level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(name)s - %(funcName)s(): %(message)s",
stream=sys.stdout,
@@ -11,10 +17,7 @@ log = logging.getLogger(__name__)
import uvicorn
from fastapi import FastAPI
import database.users
import tv.router
from auth import password
from users import routers
LOGGING_CONFIG = {
"version": 1,
@@ -42,11 +45,50 @@ LOGGING_CONFIG = {
# Apply logging config
dictConfig(LOGGING_CONFIG)
@asynccontextmanager
async def lifespan(app: FastAPI):
# Not needed if you setup a migration system like Alembic
await create_db_and_tables()
yield
database.init_db()
app = FastAPI(root_path="/api/v1")
app.include_router(routers.router, tags=["users"])
app.include_router(password.router, tags=["authentication"])
app.include_router(tv.router.router, tags=["tv"])
app = FastAPI(root_path="/api/v1", lifespan=lifespan)
app.include_router(
fastapi_users.get_auth_router(bearer_auth_backend),
prefix="/auth/jwt",
tags=["auth"]
)
app.include_router(
fastapi_users.get_auth_router(bearer_auth_backend),
prefix="/auth/cookie",
tags=["auth"]
)
app.include_router(
fastapi_users.get_register_router(UserRead, UserCreate),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_reset_password_router(),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_verify_router(UserRead),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_users_router(UserRead, UserUpdate),
prefix="/users",
tags=["users"],
)
app.include_router(
tv.router.router,
tags=["tv"])
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=5049, log_config=LOGGING_CONFIG)