39 lines
861 B
Python
39 lines
861 B
Python
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
# Shared properties
|
|
class CartItemBase(BaseModel):
|
|
product_id: int
|
|
quantity: int = Field(..., gt=0)
|
|
|
|
# Properties to receive on cart item creation
|
|
class CartItemCreate(CartItemBase):
|
|
pass
|
|
|
|
# Properties to receive on cart item update
|
|
class CartItemUpdate(BaseModel):
|
|
quantity: int = Field(..., gt=0)
|
|
|
|
# Properties shared by models stored in DB
|
|
class CartItemInDBBase(CartItemBase):
|
|
id: int
|
|
user_id: int
|
|
unit_price: float
|
|
created_at: datetime
|
|
updated_at: Optional[datetime] = None
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
# Properties to return to client
|
|
class CartItem(CartItemInDBBase):
|
|
pass
|
|
|
|
# Properties to return for cart summary
|
|
class CartSummary(BaseModel):
|
|
items: List[CartItem]
|
|
total: float
|