
- Set up project structure and FastAPI application - Create database models for users, products, and inventory - Configure SQLAlchemy and Alembic for database management - Implement JWT authentication - Create API endpoints for user, product, and inventory management - Add admin-only routes and authorization middleware - Add health check endpoint - Update README with documentation - Lint and fix code issues
59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
import enum
|
|
import uuid
|
|
|
|
from sqlalchemy import (
|
|
Column,
|
|
DateTime,
|
|
Enum,
|
|
ForeignKey,
|
|
Integer,
|
|
String,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class InventoryStatus(str, enum.Enum):
|
|
"""Enum for inventory status."""
|
|
IN_STOCK = "in_stock"
|
|
LOW_STOCK = "low_stock"
|
|
OUT_OF_STOCK = "out_of_stock"
|
|
DISCONTINUED = "discontinued"
|
|
|
|
|
|
class InventoryItem(Base):
|
|
"""Inventory item model."""
|
|
__tablename__ = "inventory_items"
|
|
|
|
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
|
quantity = Column(Integer, default=0, nullable=False)
|
|
status = Column(Enum(InventoryStatus), default=InventoryStatus.OUT_OF_STOCK, nullable=False)
|
|
location = Column(String, nullable=True)
|
|
notes = Column(Text, nullable=True)
|
|
|
|
# Foreign keys
|
|
product_id = Column(String, ForeignKey("products.id"), nullable=False)
|
|
|
|
# Relationships
|
|
product = relationship("Product", back_populates="inventory_items")
|
|
|
|
# Audit timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False)
|
|
|
|
|
|
class InventoryTransaction(Base):
|
|
"""Inventory transaction model for tracking inventory changes."""
|
|
__tablename__ = "inventory_transactions"
|
|
|
|
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
|
product_id = Column(String, ForeignKey("products.id"), nullable=False)
|
|
quantity_change = Column(Integer, nullable=False) # Positive for additions, negative for subtractions
|
|
notes = Column(Text, nullable=True)
|
|
transaction_by = Column(String, ForeignKey("users.id"), nullable=True)
|
|
|
|
# Audit timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False) |