Add admin panel, cart, checkout, and digital key delivery

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
orohi
2026-07-25 05:32:05 +03:00
co-authored by Cursor
parent 08cc4b0f1b
commit 54eaff4c70
32 changed files with 1982 additions and 105 deletions
+18 -36
View File
@@ -2,17 +2,16 @@ import time
from contextlib import asynccontextmanager
from pathlib import Path
from fastapi import Depends, FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from sqlalchemy import select
from sqlalchemy.exc import OperationalError
from sqlalchemy.orm import Session
from starlette.middleware.sessions import SessionMiddleware
from app.config import get_settings
from app.database import Base, engine, get_db
from app.models import Category, Product
from app.database import Base, engine
from app.routers import admin as admin_router
from app.routers import shop as shop_router
from app.seed import seed_if_empty
BASE_DIR = Path(__file__).resolve().parent
@@ -46,7 +45,15 @@ async def lifespan(_: FastAPI):
app = FastAPI(title=settings.app_name, lifespan=lifespan)
app.add_middleware(
SessionMiddleware,
secret_key=settings.secret_key,
session_cookie="pitopn_session",
same_site="lax",
https_only=False,
)
app.mount("/static", StaticFiles(directory=BASE_DIR / "static"), name="static")
templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
@@ -61,37 +68,12 @@ def format_price(value) -> str:
templates.env.filters["rub"] = format_price
shop_router.setup(templates)
admin_router.setup(templates)
app.include_router(shop_router.router)
app.include_router(admin_router.router)
@app.get("/health")
def health() -> dict[str, str]:
return {"status": "ok"}
@app.get("/", response_class=HTMLResponse)
def home(request: Request, db: Session = Depends(get_db)):
categories = db.scalars(
select(Category).order_by(Category.sort_order, Category.name)
).all()
featured = db.scalars(
select(Product)
.where(Product.is_active.is_(True), Product.is_featured.is_(True))
.order_by(Product.id)
.limit(4)
).all()
products = db.scalars(
select(Product)
.where(Product.is_active.is_(True))
.order_by(Product.is_featured.desc(), Product.id)
.limit(12)
).all()
return templates.TemplateResponse(
request,
"index.html",
{
"app_name": settings.app_name,
"categories": categories,
"featured": featured,
"products": products,
},
)