Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] authored and Delemangi committed Mar 3, 2024
1 parent aaf829c commit 47673b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 11 additions & 2 deletions backend/app/database.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
from collections.abc import AsyncGenerator

from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine, AsyncEngine
from sqlalchemy.ext.asyncio import (
AsyncSession,
async_sessionmaker,
create_async_engine,
AsyncEngine,
)

from app.auth.models import Role # noqa: F401
from app.file_transfer.models import File, Webhook # noqa: F401
Expand All @@ -10,6 +15,7 @@
engine: AsyncEngine | None = None
SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL")


def get_engine() -> AsyncEngine:
global engine

Expand All @@ -22,6 +28,8 @@ def get_engine() -> AsyncEngine:


async_session_maker: None | async_sessionmaker = None


def get_session_maker():
global async_session_maker
if async_session_maker is None:
Expand All @@ -30,12 +38,13 @@ def get_session_maker():
)
return async_session_maker


async def initialize_database() -> None:
async with get_engine().begin() as conn:
await conn.run_sync(Base.metadata.drop_all)
await conn.run_sync(Base.metadata.create_all)


async def get_async_session() -> AsyncGenerator[AsyncSession, None]:
async with get_session_maker() as session: # type: ignore
async with get_session_maker() as session: # type: ignore
yield session
5 changes: 5 additions & 0 deletions backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from app.settings import APISettings


@asynccontextmanager
async def lifespan(_: FastAPI) -> AsyncGenerator[None, None]:
print("Application is starting up")
Expand Down Expand Up @@ -41,15 +42,19 @@ def make_app() -> FastAPI:
app = FastAPI(lifespan=lifespan)
app.include_router(auth_router, prefix="/auth")
app.include_router(file_router, prefix="/files")

@app.get("/")
async def root() -> str:
return "Hello World"

return app


def run() -> None:
app = make_app()
settings = APISettings()
uvicorn.run(app, host=settings.host, port=settings.port, log_level="info")


if __name__ == "__main__":
run()
1 change: 1 addition & 0 deletions backend/app/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pydantic_settings import BaseSettings, SettingsConfigDict


class APISettings(BaseSettings):
host: str = "0.0.0.0"
port: int = 8002

0 comments on commit 47673b6

Please sign in to comment.