-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (31 loc) · 1.36 KB
/
Copy pathmain.py
File metadata and controls
40 lines (31 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import os
import uvicorn
import logging
from dotenv import load_dotenv
from infrastructure.database import PostgresLedgerRepo, init_db
from application.use_cases import TransferUseCase
from application.queries import GetBalanceQuery, GetStatementQuery
from presentation import create_app
# Load environment variables
load_dotenv()
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
)
logger = logging.getLogger("python-ledger")
async def app_factory():
database_url = os.getenv("DATABASE_URL", "postgresql+asyncpg://postgres:postgres@localhost:5432/ledger")
logger.info("Initializing database...")
_, session_factory = await init_db(database_url)
repo = PostgresLedgerRepo(session_factory)
transfer_use_case = TransferUseCase(repo)
get_balance_query = GetBalanceQuery(repo)
get_statement_query = GetStatementQuery(repo)
logger.info("Creating FastAPI application...")
return create_app(transfer_use_case, get_balance_query, get_statement_query)
if __name__ == "__main__":
port = int(os.getenv("PORT", 3000))
# Note: reload=True should not be used with factory path in some production environments,
# but is extremely helpful for local development.
uvicorn.run("main:app_factory", host="0.0.0.0", port=port, factory=True, reload=True)