from typing import List from sqlalchemy.orm import Session from app.crud.base import CRUDBase from app.models.inventory import Inventory from app.schemas.inventory import InventoryCreate, InventoryUpdate class CRUDInventory(CRUDBase[Inventory, InventoryCreate, InventoryUpdate]): def get_by_product_id(self, db: Session, *, product_id: int) -> Inventory: return db.query(Inventory).filter(Inventory.product_id == product_id).first() def update_quantity(self, db: Session, *, inventory_id: int, quantity_change: int) -> Inventory: inventory = self.get(db, id=inventory_id) if inventory: inventory.quantity += quantity_change db.add(inventory) db.commit() db.refresh(inventory) return inventory def get_low_stock(self, db: Session, *, threshold: int = 10, skip: int = 0, limit: int = 100) -> List[Inventory]: return db.query(Inventory).filter(Inventory.quantity <= threshold).offset(skip).limit(limit).all() inventory = CRUDInventory(Inventory)