Automated Action 54bf9880b9 Implement Small Business Inventory Management System
This commit implements a comprehensive inventory management system for small businesses using FastAPI and SQLAlchemy. Features include:
- Product and category management
- Inventory tracking across multiple locations
- Supplier management
- Purchase management
- Transaction tracking for inventory movements
- Complete API documentation

generated with BackendIM... (backend.im)
2025-05-12 12:55:31 +00:00

53 lines
1.9 KiB
Python

from typing import Generator
from fastapi import Depends, HTTPException, status
from sqlalchemy.orm import Session
from app.db.session import get_db
from app.models.product import Product, Category
from app.models.inventory import InventoryItem, Location
from app.models.supplier import Supplier, Purchase
# Common dependencies
def get_product(db: Session = Depends(get_db), product_id: int = None):
if product_id:
product = db.query(Product).filter(Product.id == product_id).first()
if not product:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Product with ID {product_id} not found"
)
return product
return None
def get_category(db: Session = Depends(get_db), category_id: int = None):
if category_id:
category = db.query(Category).filter(Category.id == category_id).first()
if not category:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Category with ID {category_id} not found"
)
return category
return None
def get_location(db: Session = Depends(get_db), location_id: int = None):
if location_id:
location = db.query(Location).filter(Location.id == location_id).first()
if not location:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Location with ID {location_id} not found"
)
return location
return None
def get_supplier(db: Session = Depends(get_db), supplier_id: int = None):
if supplier_id:
supplier = db.query(Supplier).filter(Supplier.id == supplier_id).first()
if not supplier:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Supplier with ID {supplier_id} not found"
)
return supplier
return None