diff --git a/backend/app/routers/views.py b/backend/app/routers/views.py index 712d3e8..f3ccf4d 100644 --- a/backend/app/routers/views.py +++ b/backend/app/routers/views.py @@ -27,6 +27,7 @@ from ..schemas import ( LocationNeeds, MovementOut, ShoppingItem, + ShoppingListAll, ) from ..services.conversion import BASE_OF_KIND, article_unit, display_unit_info from ..services.stock import ( @@ -166,6 +167,20 @@ def shopping_list_by_location( 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) def location_contents( code: str, diff --git a/backend/app/schemas.py b/backend/app/schemas.py index 05f9788..23f112d 100644 --- a/backend/app/schemas.py +++ b/backend/app/schemas.py @@ -693,6 +693,14 @@ class LocationNeeds(BaseModel): 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): """Ein Artikel mit seinem Bestand an einem Lagerort (in Artikeleinheiten).""" product_id: int