Files
2026-08-08 20:31:58 +02:00

40 lines
1.4 KiB
Python

"""Preisvergleich: Übersicht, Verlauf je Artikel, Kurzhinweise."""
from fastapi import APIRouter, HTTPException, status
from sqlalchemy import select
from app.deps import DbSession
from app.models import Article
from app.permissions import ReadableList
from app.prices import article_prices, hints, overview
from app.schemas_shopping import ArticlePrices, PriceHint, PriceOverview
router = APIRouter(prefix="/api/lists/{list_id}", tags=["prices"])
@router.get("/prices", response_model=PriceOverview)
def price_overview(lst: ReadableList, db: DbSession):
"""Vergleichstabelle: je Artikel der jüngste Preis in jedem Markt."""
return overview(db, lst.id)
@router.get("/price-hints", response_model=list[PriceHint])
def price_hints(lst: ReadableList, db: DbSession):
"""Kompakte Fassung für die Listenansicht - nur Artikel, bei denen
sich die Märkte tatsächlich unterscheiden."""
return hints(db, lst.id)
@router.get("/articles/{article_id}/prices", response_model=ArticlePrices)
def article_price_history(article_id: str, lst: ReadableList, db: DbSession):
article = db.scalar(
select(Article).where(
Article.id == article_id,
Article.list_id == lst.id,
Article.deleted_at.is_(None),
)
)
if article is None:
raise HTTPException(status.HTTP_404_NOT_FOUND, "Artikel nicht gefunden")
return article_prices(db, lst.id, article)