Automated Action a17fe518a9 Implement Small Business Inventory Management System
This commit includes:
- Project structure setup with FastAPI and SQLite
- Database models and schemas for inventory management
- CRUD operations for all entities
- API endpoints for product, category, supplier, and inventory management
- User authentication with JWT tokens
- Initial database migration
- Comprehensive README with setup instructions
2025-06-17 19:02:35 +00:00

36 lines
1.4 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_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)