Files
work-volume-tracker/app/main.py
T
Александр Арсентьев 9828d2b0a1 wip: start KS-2 implementation
2026-09-26 13:03:46 +03:00

60 lines
2.1 KiB
Python

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi.responses import RedirectResponse
from pathlib import Path
# Import routers
from app.routers import projects, boq as boq_router, daily_reports, agreements, ks2
# Import models to ensure they're registered
from app.models import project as project_models, boq as boq_models
from app.models import daily_report as daily_report_models
from app.models import work_journal as work_journal_models
from app.models import agreement as agreement_models
from app.models import ks2 as ks2_models
# Initialize database
from app.database.database import engine
from app.database.database import Base
Base.metadata.create_all(bind=engine)
from app.database.migrations import run_migrations
run_migrations(engine)
app = FastAPI(
title="Work Volume Tracker",
description="A simple local web application for tracking completed work volumes in projects",
version="0.1.0"
)
# Resolve app resources relative to this module, not to the process working directory.
APP_DIR = Path(__file__).resolve().parent
app.mount("/static", StaticFiles(directory=APP_DIR / "static"), name="static")
# Create templates
templates = Jinja2Templates(directory=APP_DIR / "templates")
from app.utils.formatters import format_money
templates.env.filters["money"] = format_money
app.templates = templates
# Include routers
app.include_router(projects.router, prefix="/projects", tags=["projects"])
app.include_router(boq_router.router, prefix="/boq", tags=["boq"])
app.include_router(daily_reports.router, prefix="/projects", tags=["daily-reports"])
app.include_router(agreements.router, prefix="/projects", tags=["agreements"])
app.include_router(ks2.router, prefix="/projects", tags=["ks2"])
@app.get("/", include_in_schema=False)
async def read_root():
return RedirectResponse(url="/projects/", status_code=307)
@app.get("/health")
async def health_check():
return {"status": "healthy"}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)