Schritt 1: Fundament der Lebensmittel-Lagerverwaltung (Pantry)
Backend (FastAPI + PostgreSQL): Chargen mit MHD, FEFO-Auslagern, Einheiten-Umrechnung (Stueck/g/ml + Packungen), Open-Food-Facts-Lookup mit lokalem Fallback, JWT-Auth mit Rollen (Admin/Nutzer), erster Admin beim Setup, Einkaufsliste, Ablaufwarnung, Lagerorte, pytest fuer FEFO. Web-UI (React/Vite): Login, Dashboard, Ein-/Auslagern, Produkte, Lagerorte, Benutzerverwaltung, Einkaufsliste - rollenabhaengig. Deploy: docker-compose + install.sh (Docker-Autoinstall, Secrets), README und Roadmap fuer Schritt 2 (iOS) und Schritt 3. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
34
backend/app/crud.py
Normal file
34
backend/app/crud.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""Kleine gemeinsame Helfer für Router."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .models import Product
|
||||
from .schemas import ProductOut
|
||||
from .services.stock import current_stock
|
||||
|
||||
|
||||
def product_to_out(db: Session, product: Product) -> ProductOut:
|
||||
out = ProductOut.model_validate(product)
|
||||
out.stock = current_stock(db, product.id)
|
||||
return out
|
||||
|
||||
|
||||
def resolve_product(
|
||||
db: Session, product_id: int | None, barcode: str | None
|
||||
) -> Product:
|
||||
"""Findet ein Produkt per ID oder Barcode; wirft 404, wenn keins passt."""
|
||||
product: Product | None = None
|
||||
if product_id is not None:
|
||||
product = db.get(Product, product_id)
|
||||
elif barcode:
|
||||
product = db.query(Product).filter(Product.barcode == barcode).first()
|
||||
else:
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST, "product_id oder barcode erforderlich"
|
||||
)
|
||||
if product is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, "Produkt nicht gefunden")
|
||||
return product
|
||||
Reference in New Issue
Block a user