2025-06-05 23:45:53 +00:00

33 lines
1.3 KiB
Python

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_category(
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(
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 == True).offset(skip).limit(limit).all()
product = CRUDProduct(Product)