from typing import List, Optional from sqlalchemy.orm import Session from app.crud.base import CRUDBase from app.models.product import Product from app.schemas.product import ProductCreate, ProductUpdate class CRUDProduct(CRUDBase[Product, ProductCreate, ProductUpdate]): def get_by_sku(self, db: Session, *, sku: str) -> Optional[Product]: return db.query(Product).filter(Product.sku == sku).first() def get_by_barcode(self, db: Session, *, barcode: str) -> Optional[Product]: return db.query(Product).filter(Product.barcode == barcode).first() def get_by_name(self, db: Session, *, name: str) -> List[Product]: return db.query(Product).filter(Product.name.ilike(f"%{name}%")).all() def get_by_category_id( self, db: Session, *, category_id: int, skip: int = 0, limit: int = 100 ) -> List[Product]: return db.query(Product).filter(Product.category_id == category_id).offset(skip).limit(limit).all() def get_by_supplier_id( self, db: Session, *, supplier_id: int, skip: int = 0, limit: int = 100 ) -> List[Product]: return db.query(Product).filter(Product.supplier_id == supplier_id).offset(skip).limit(limit).all() def get_active( self, db: Session, *, skip: int = 0, limit: int = 100 ) -> List[Product]: return db.query(Product).filter(Product.is_active).offset(skip).limit(limit).all() product = CRUDProduct(Product)