41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import logging
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from app.api.v1.api import api_router
|
|
from app.api.v1.web import web_router
|
|
from app.config import settings
|
|
from migrations.runner import MigrationRunner
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
logging.info(f"\n\n{settings.get_postgres_database_url()}")
|
|
runner = MigrationRunner(settings.get_postgres_database_url())
|
|
await runner.run_migrations()
|
|
yield
|
|
|
|
|
|
# TODO: (#ToLearn) Почитать про lifespan в FastAPI приложениях
|
|
app = FastAPI(
|
|
title="Fitness Parser API",
|
|
description="API for parsing fitness training data from various sources",
|
|
version="0.1.0",
|
|
lifespan=lifespan
|
|
)
|
|
|
|
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
|
|
|
templates = Jinja2Templates(directory="app/templates")
|
|
|
|
# Include routers
|
|
app.include_router(api_router, prefix="/api/v1")
|
|
app.include_router(web_router, prefix="/app")
|
|
|
|
|
|
@app.get("/")
|
|
async def root():
|
|
return {"message": "Fitness Parser API", "version": "0.1.0"}
|