Initial project scaffold: FastAPI backend + Svelte 5 frontend
Backend (uv): FastAPI app with routers (foods, log, targets, OFF proxy), SQLAlchemy models, Pydantic schemas, migration runner + 0001 initial schema, example pytest suite (7 tests). Frontend (npm): Vite 7 + Svelte 5 runes, lib/ (api, stores, scanner, format) per spec §7, placeholder components, example vitest suite (4 tests). SPEC.md §1: registered uvicorn and Vitest (rule §8.3.3).
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
"""Targets router (spec §3.4)."""
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from database import get_db
|
||||
from models import Target
|
||||
from schemas import TargetRead
|
||||
|
||||
router = APIRouter(prefix="/api/targets", tags=["targets"])
|
||||
|
||||
|
||||
@router.get("", response_model=list[TargetRead])
|
||||
def list_targets(db: Session = Depends(get_db)):
|
||||
return db.scalars(select(Target).order_by(Target.start_date)).all()
|
||||
|
||||
|
||||
@router.get("/current", response_model=TargetRead)
|
||||
def current_target(db: Session = Depends(get_db)):
|
||||
target = db.scalar(select(Target).where(Target.end_date.is_(None)))
|
||||
if target is None:
|
||||
raise HTTPException(status_code=404, detail="No active target")
|
||||
return target
|
||||
Reference in New Issue
Block a user