
- Created complete RESTful API for inventory management - Set up database models for items, categories, suppliers, and transactions - Implemented user authentication with JWT tokens - Added transaction tracking for inventory movements - Created comprehensive API endpoints for all CRUD operations - Set up Alembic for database migrations - Added input validation and error handling - Created detailed documentation in README
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
from typing import List, Optional
|
|
import uuid
|
|
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.crud.base import CRUDBase
|
|
from app.models.item import Item
|
|
from app.schemas.item import ItemCreate, ItemUpdate
|
|
|
|
|
|
class CRUDItem(CRUDBase[Item, ItemCreate, ItemUpdate]):
|
|
def create(self, db: Session, *, obj_in: ItemCreate) -> Item:
|
|
db_obj = Item(
|
|
id=str(uuid.uuid4()),
|
|
name=obj_in.name,
|
|
description=obj_in.description,
|
|
sku=obj_in.sku,
|
|
quantity=obj_in.quantity,
|
|
unit_price=obj_in.unit_price,
|
|
location=obj_in.location,
|
|
min_stock_level=obj_in.min_stock_level,
|
|
category_id=obj_in.category_id,
|
|
supplier_id=obj_in.supplier_id,
|
|
)
|
|
db.add(db_obj)
|
|
db.commit()
|
|
db.refresh(db_obj)
|
|
return db_obj
|
|
|
|
def get_by_sku(self, db: Session, *, sku: str) -> Optional[Item]:
|
|
return db.query(Item).filter(Item.sku == sku).first()
|
|
|
|
def get_by_category(self, db: Session, *, category_id: str, skip: int = 0, limit: int = 100) -> List[Item]:
|
|
return db.query(Item).filter(Item.category_id == category_id).offset(skip).limit(limit).all()
|
|
|
|
def get_by_supplier(self, db: Session, *, supplier_id: str, skip: int = 0, limit: int = 100) -> List[Item]:
|
|
return db.query(Item).filter(Item.supplier_id == supplier_id).offset(skip).limit(limit).all()
|
|
|
|
def get_low_stock_items(self, db: Session, *, skip: int = 0, limit: int = 100) -> List[Item]:
|
|
return db.query(Item).filter(Item.quantity <= Item.min_stock_level).offset(skip).limit(limit).all()
|
|
|
|
|
|
item = CRUDItem(Item) |