
This API provides endpoints for: - Product and inventory management - Customer management - Order processing - Payment processing with Stripe integration - User authentication generated with BackendIM... (backend.im)
39 lines
1.7 KiB
Python
39 lines
1.7 KiB
Python
from sqlalchemy import Column, Integer, String, Float, DateTime, ForeignKey, Table
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
|
|
from app.db.base_class import Base
|
|
|
|
|
|
class Order(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
customer_id = Column(Integer, ForeignKey("customer.id"))
|
|
order_number = Column(String, unique=True, index=True)
|
|
status = Column(String, default="pending") # pending, paid, shipped, delivered, cancelled
|
|
total_amount = Column(Float)
|
|
payment_intent_id = Column(String, nullable=True)
|
|
payment_status = Column(String, default="unpaid") # unpaid, paid, refunded
|
|
shipping_address = Column(String, nullable=True)
|
|
shipping_city = Column(String, nullable=True)
|
|
shipping_state = Column(String, nullable=True)
|
|
shipping_zip = Column(String, nullable=True)
|
|
shipping_country = Column(String, nullable=True)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
updated_at = Column(DateTime(timezone=True), onupdate=func.now())
|
|
|
|
# Relationships
|
|
customer = relationship("Customer", back_populates="orders")
|
|
items = relationship("OrderItem", back_populates="order")
|
|
|
|
|
|
class OrderItem(Base):
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
order_id = Column(Integer, ForeignKey("order.id"))
|
|
product_id = Column(Integer, ForeignKey("product.id"))
|
|
quantity = Column(Integer, default=1)
|
|
unit_price = Column(Float)
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# Relationships
|
|
order = relationship("Order", back_populates="items")
|
|
product = relationship("Product", back_populates="order_items") |