
- Added comprehensive book management with CRUD operations - Implemented inventory tracking with stock management and reservations - Created order management system with status tracking - Integrated Stripe payment processing with payment intents - Added SQLite database with SQLAlchemy ORM and Alembic migrations - Implemented health check and API documentation endpoints - Added comprehensive error handling and validation - Configured CORS middleware for frontend integration
37 lines
1.4 KiB
Python
37 lines
1.4 KiB
Python
from sqlalchemy import Column, Integer, String, Float, DateTime, Enum, ForeignKey, Text
|
|
from sqlalchemy.sql import func
|
|
from sqlalchemy.orm import relationship
|
|
import enum
|
|
from app.db.base import Base
|
|
|
|
class OrderStatus(enum.Enum):
|
|
PENDING = "pending"
|
|
CONFIRMED = "confirmed"
|
|
SHIPPED = "shipped"
|
|
DELIVERED = "delivered"
|
|
CANCELLED = "cancelled"
|
|
|
|
class Order(Base):
|
|
__tablename__ = "orders"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
customer_email = Column(String(255), nullable=False)
|
|
customer_name = Column(String(255), nullable=False)
|
|
customer_address = Column(Text, nullable=False)
|
|
total_amount = Column(Float, nullable=False)
|
|
status = Column(Enum(OrderStatus), default=OrderStatus.PENDING)
|
|
stripe_payment_intent_id = Column(String(255), nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
class OrderItem(Base):
|
|
__tablename__ = "order_items"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
order_id = Column(Integer, ForeignKey("orders.id"), nullable=False)
|
|
book_id = Column(Integer, ForeignKey("books.id"), nullable=False)
|
|
quantity = Column(Integer, nullable=False)
|
|
price = Column(Float, nullable=False)
|
|
|
|
order = relationship("Order", backref="items")
|
|
book = relationship("Book") |