
- 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
54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
import uuid
|
|
|
|
from sqlalchemy import (
|
|
Boolean,
|
|
Column,
|
|
DateTime,
|
|
Float,
|
|
ForeignKey,
|
|
String,
|
|
Text,
|
|
)
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base import Base
|
|
|
|
|
|
class Category(Base):
|
|
"""Category model for product categorization."""
|
|
__tablename__ = "categories"
|
|
|
|
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
|
name = Column(String, unique=True, index=True, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
|
|
# Relationships
|
|
products = relationship("Product", back_populates="category")
|
|
|
|
# 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 Product(Base):
|
|
"""Product model."""
|
|
__tablename__ = "products"
|
|
|
|
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
|
name = Column(String, index=True, nullable=False)
|
|
description = Column(Text, nullable=True)
|
|
price = Column(Float, nullable=False)
|
|
sku = Column(String, unique=True, index=True, nullable=False)
|
|
is_active = Column(Boolean, default=True)
|
|
|
|
# Foreign keys
|
|
category_id = Column(String, ForeignKey("categories.id"), nullable=True)
|
|
|
|
# Relationships
|
|
category = relationship("Category", back_populates="products")
|
|
inventory_items = relationship("InventoryItem", back_populates="product")
|
|
|
|
# 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) |