Automated Action 538a985c8e Build e-commerce API with FastAPI and SQLite
Create a complete e-commerce application with the following features:
- User authentication and authorization
- Product and category management
- Shopping cart functionality
- Order processing
- Database migrations with Alembic
- Comprehensive documentation
2025-05-26 11:05:27 +00:00

21 lines
881 B
Python

from datetime import datetime
from sqlalchemy import Column, String, Integer, DateTime, ForeignKey, UniqueConstraint
from sqlalchemy.orm import relationship
from app.db.base_class import Base
class CartItem(Base):
id = Column(String, primary_key=True, index=True)
cart_id = Column(String, ForeignKey("cart.id"))
product_id = Column(String, ForeignKey("product.id"))
quantity = Column(Integer, nullable=False, default=1)
created_at = Column(DateTime, default=datetime.utcnow)
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
# Ensure each product can only be in the cart once
__table_args__ = (UniqueConstraint('cart_id', 'product_id', name='_cart_product_uc'),)
# Relationships
cart = relationship("Cart", back_populates="items")
product = relationship("Product", back_populates="cart_items")