Add admin panel, cart, checkout, and digital key delivery
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+66
-2
@@ -1,8 +1,17 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from sqlalchemy import Boolean, DateTime, Numeric, String, Text, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
Numeric,
|
||||
String,
|
||||
Text,
|
||||
func,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
||||
@@ -35,3 +44,58 @@ class Product(Base):
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
keys: Mapped[list["ProductKey"]] = relationship(back_populates="product")
|
||||
|
||||
|
||||
class ProductKey(Base):
|
||||
__tablename__ = "product_keys"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), index=True)
|
||||
code: Mapped[str] = mapped_column(Text)
|
||||
is_sold: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
||||
order_id: Mapped[int | None] = mapped_column(ForeignKey("orders.id"), nullable=True)
|
||||
sold_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
|
||||
product: Mapped["Product"] = relationship(back_populates="keys")
|
||||
order: Mapped["Order | None"] = relationship(back_populates="keys")
|
||||
|
||||
|
||||
class Order(Base):
|
||||
__tablename__ = "orders"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
public_id: Mapped[str] = mapped_column(String(32), unique=True, index=True)
|
||||
email: Mapped[str] = mapped_column(String(255), index=True)
|
||||
status: Mapped[str] = mapped_column(String(32), default="pending", index=True)
|
||||
total: Mapped[Decimal] = mapped_column(Numeric(12, 2), default=Decimal("0.00"))
|
||||
customer_note: Mapped[str] = mapped_column(Text, default="")
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
paid_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
delivered_at: Mapped[datetime | None] = mapped_column(
|
||||
DateTime(timezone=True), nullable=True
|
||||
)
|
||||
|
||||
items: Mapped[list["OrderItem"]] = relationship(back_populates="order")
|
||||
keys: Mapped[list["ProductKey"]] = relationship(back_populates="order")
|
||||
|
||||
|
||||
class OrderItem(Base):
|
||||
__tablename__ = "order_items"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
order_id: Mapped[int] = mapped_column(ForeignKey("orders.id"), index=True)
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey("products.id"), index=True)
|
||||
title: Mapped[str] = mapped_column(String(200))
|
||||
unit_price: Mapped[Decimal] = mapped_column(Numeric(10, 2))
|
||||
quantity: Mapped[int] = mapped_column(Integer, default=1)
|
||||
delivered_codes: Mapped[str] = mapped_column(Text, default="")
|
||||
|
||||
order: Mapped["Order"] = relationship(back_populates="items")
|
||||
product: Mapped["Product"] = relationship()
|
||||
|
||||
Reference in New Issue
Block a user