Spaces:
Sleeping
Sleeping
Upload app/schemas/cart.py
Browse files- app/schemas/cart.py +47 -0
app/schemas/cart.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import List, Optional
|
| 2 |
+
from pydantic import BaseModel, Field
|
| 3 |
+
|
| 4 |
+
from app.schemas.product import ProductListItem
|
| 5 |
+
|
| 6 |
+
# --- Cart Items ---
|
| 7 |
+
class CartItemCreate(BaseModel):
|
| 8 |
+
product_id: int
|
| 9 |
+
quantity: int = Field(default=1, ge=1)
|
| 10 |
+
|
| 11 |
+
class CartItemUpdate(BaseModel):
|
| 12 |
+
quantity: int = Field(ge=1)
|
| 13 |
+
|
| 14 |
+
class CartItemResponse(BaseModel):
|
| 15 |
+
id: int
|
| 16 |
+
cart_id: int
|
| 17 |
+
product_id: int
|
| 18 |
+
quantity: int
|
| 19 |
+
unit_price: float
|
| 20 |
+
total_price: float
|
| 21 |
+
product: ProductListItem
|
| 22 |
+
|
| 23 |
+
model_config = {"from_attributes": True}
|
| 24 |
+
|
| 25 |
+
# --- Coupons ---
|
| 26 |
+
class CouponApply(BaseModel):
|
| 27 |
+
code: str
|
| 28 |
+
|
| 29 |
+
class CouponResponse(BaseModel):
|
| 30 |
+
code: str
|
| 31 |
+
discount_percent: float
|
| 32 |
+
|
| 33 |
+
model_config = {"from_attributes": True}
|
| 34 |
+
|
| 35 |
+
# --- Cart ---
|
| 36 |
+
class CartResponse(BaseModel):
|
| 37 |
+
id: int
|
| 38 |
+
user_id: Optional[int] = None
|
| 39 |
+
items: List[CartItemResponse]
|
| 40 |
+
subtotal: float
|
| 41 |
+
tax: float
|
| 42 |
+
shipping_cost: float
|
| 43 |
+
discount_amount: float
|
| 44 |
+
total: float
|
| 45 |
+
applied_coupon: Optional[CouponResponse] = None
|
| 46 |
+
|
| 47 |
+
model_config = {"from_attributes": True}
|