Backend: kombinierter Einkaufslisten-Endpunkt /shopping-list/all

Liefert Produkte, Gruppen und Bedarfe je Lagerort in einem Aufruf - dieselben
drei Quellen, die die Oberflaeche ohnehin zusammenfuehrt. Erspart API-Nutzern
drei getrennte Requests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Scarriffle
2026-07-29 16:08:12 +02:00
parent 66a52bfecb
commit a04315db21
2 changed files with 23 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ from ..schemas import (
LocationNeeds, LocationNeeds,
MovementOut, MovementOut,
ShoppingItem, ShoppingItem,
ShoppingListAll,
) )
from ..services.conversion import BASE_OF_KIND, article_unit, display_unit_info from ..services.conversion import BASE_OF_KIND, article_unit, display_unit_info
from ..services.stock import ( from ..services.stock import (
@@ -166,6 +167,20 @@ def shopping_list_by_location(
return result return result
@router.get("/shopping-list/all", response_model=ShoppingListAll)
def shopping_list_all(
db: Session = Depends(get_db), user: User = Depends(get_current_user)
) -> ShoppingListAll:
"""Komplette Einkaufsliste in einem Aufruf: Produkte, Gruppen und Bedarfe je
Lagerort genau die drei Quellen, die auch die Oberfläche zusammenführt.
Erspart drei getrennte Abfragen."""
return ShoppingListAll(
products=shopping_list(db, user),
groups=group_shopping_list(db, user),
by_location=shopping_list_by_location(db, user),
)
@router.get("/location/{code}", response_model=LocationContents) @router.get("/location/{code}", response_model=LocationContents)
def location_contents( def location_contents(
code: str, code: str,

View File

@@ -693,6 +693,14 @@ class LocationNeeds(BaseModel):
groups: list[LocationNeedGroup] = [] groups: list[LocationNeedGroup] = []
class ShoppingListAll(BaseModel):
"""Komplette Einkaufsliste in einem Aufruf dieselben drei Quellen, die auch
die Oberfläche zusammenführt."""
products: list[ShoppingItem] = []
groups: list[GroupShoppingItem] = []
by_location: list[LocationNeeds] = []
class LocationContentEntry(BaseModel): class LocationContentEntry(BaseModel):
"""Ein Artikel mit seinem Bestand an einem Lagerort (in Artikeleinheiten).""" """Ein Artikel mit seinem Bestand an einem Lagerort (in Artikeleinheiten)."""
product_id: int product_id: int