
- Setup project structure with FastAPI application - Create database models with SQLAlchemy - Configure Alembic for database migrations - Implement CRUD operations for products, categories, suppliers - Add inventory transaction functionality - Implement user authentication with JWT - Add health check endpoint - Create comprehensive documentation
47 lines
1.5 KiB
Python
47 lines
1.5 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_low_stock_products(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Product]:
|
|
return (
|
|
db.query(Product)
|
|
.filter(Product.quantity <= Product.min_stock_level)
|
|
.offset(skip)
|
|
.limit(limit)
|
|
.all()
|
|
)
|
|
|
|
|
|
product = CRUDProduct(Product) |