Initial commit: Parking Manager
Features: - Manager-centric parking spot management - Fair assignment algorithm (parking/presence ratio) - Presence tracking calendar - Closing days (specific & weekly recurring) - Guarantees and exclusions - Authelia/LLDAP integration for SSO Stack: - FastAPI backend - SQLite database - Vanilla JS frontend - Docker deployment
This commit is contained in:
127
main.py
Normal file
127
main.py
Normal file
@@ -0,0 +1,127 @@
|
||||
"""
|
||||
Parking Manager Application
|
||||
FastAPI + SQLite + Vanilla JS
|
||||
"""
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse, RedirectResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
from app import config
|
||||
from app.routes.auth import router as auth_router
|
||||
from app.routes.users import router as users_router
|
||||
from app.routes.offices import router as offices_router
|
||||
from app.routes.managers import router as managers_router
|
||||
from app.routes.presence import router as presence_router
|
||||
from app.routes.parking import router as parking_router
|
||||
from database.connection import init_db
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""Initialize database on startup"""
|
||||
init_db()
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(title="Parking Manager", version="1.0.0", lifespan=lifespan)
|
||||
|
||||
# CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=config.ALLOWED_ORIGINS,
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# API Routes
|
||||
app.include_router(auth_router)
|
||||
app.include_router(users_router)
|
||||
app.include_router(offices_router)
|
||||
app.include_router(managers_router)
|
||||
app.include_router(presence_router)
|
||||
app.include_router(parking_router)
|
||||
|
||||
# Static Files
|
||||
app.mount("/css", StaticFiles(directory=str(config.FRONTEND_DIR / "css")), name="css")
|
||||
app.mount("/js", StaticFiles(directory=str(config.FRONTEND_DIR / "js")), name="js")
|
||||
|
||||
|
||||
# Page Routes
|
||||
@app.get("/")
|
||||
async def index():
|
||||
"""Landing page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "landing.html")
|
||||
|
||||
|
||||
@app.get("/login")
|
||||
async def login_page():
|
||||
"""Login page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "login.html")
|
||||
|
||||
|
||||
@app.get("/register")
|
||||
async def register_page():
|
||||
"""Register page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "register.html")
|
||||
|
||||
|
||||
@app.get("/dashboard")
|
||||
async def dashboard():
|
||||
"""Dashboard - redirect to team calendar"""
|
||||
return RedirectResponse(url="/team-calendar", status_code=302)
|
||||
|
||||
|
||||
@app.get("/presence")
|
||||
async def presence_page():
|
||||
"""My Presence page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "presence.html")
|
||||
|
||||
|
||||
@app.get("/team-calendar")
|
||||
async def team_calendar_page():
|
||||
"""Team Calendar page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "team-calendar.html")
|
||||
|
||||
|
||||
@app.get("/office-rules")
|
||||
async def office_rules_page():
|
||||
"""Office Rules page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "office-rules.html")
|
||||
|
||||
|
||||
@app.get("/admin/users")
|
||||
async def admin_users_page():
|
||||
"""Admin Users page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "admin-users.html")
|
||||
|
||||
|
||||
@app.get("/profile")
|
||||
async def profile_page():
|
||||
"""Profile page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "profile.html")
|
||||
|
||||
|
||||
@app.get("/settings")
|
||||
async def settings_page():
|
||||
"""Settings page"""
|
||||
return FileResponse(config.FRONTEND_DIR / "pages" / "settings.html")
|
||||
|
||||
|
||||
@app.get("/favicon.svg")
|
||||
async def favicon():
|
||||
"""Favicon"""
|
||||
return FileResponse(config.FRONTEND_DIR / "favicon.svg", media_type="image/svg+xml")
|
||||
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
"""Health check"""
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run("main:app", host=config.HOST, port=config.PORT, reload=True)
|
||||
Reference in New Issue
Block a user