Spaces:
Sleeping
Sleeping
Upload app/schemas/product.py
Browse files- app/schemas/product.py +128 -0
app/schemas/product.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime
|
| 2 |
+
from typing import Optional, List
|
| 3 |
+
|
| 4 |
+
from pydantic import BaseModel, Field
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# --- Category Schemas ---
|
| 8 |
+
|
| 9 |
+
class CategoryCreate(BaseModel):
|
| 10 |
+
name_ar: str = Field(..., min_length=1, max_length=255)
|
| 11 |
+
name_en: str = Field(..., min_length=1, max_length=255)
|
| 12 |
+
icon: Optional[str] = None
|
| 13 |
+
sort_order: int = 0
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class CategoryResponse(BaseModel):
|
| 17 |
+
id: int
|
| 18 |
+
name_ar: str
|
| 19 |
+
name_en: str
|
| 20 |
+
icon: Optional[str] = None
|
| 21 |
+
sort_order: int
|
| 22 |
+
|
| 23 |
+
model_config = {"from_attributes": True}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# --- Product Image Schemas ---
|
| 27 |
+
|
| 28 |
+
class ProductImageResponse(BaseModel):
|
| 29 |
+
id: int
|
| 30 |
+
image_url: str
|
| 31 |
+
alt_text: Optional[str] = None
|
| 32 |
+
sort_order: int
|
| 33 |
+
|
| 34 |
+
model_config = {"from_attributes": True}
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class ProductImageCreate(BaseModel):
|
| 38 |
+
image_url: str = Field(..., max_length=1000)
|
| 39 |
+
alt_text: Optional[str] = None
|
| 40 |
+
sort_order: int = 0
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
# --- Product Schemas ---
|
| 44 |
+
|
| 45 |
+
class ProductCreate(BaseModel):
|
| 46 |
+
name_ar: str = Field(..., min_length=1, max_length=500)
|
| 47 |
+
name_en: str = Field(..., min_length=1, max_length=500)
|
| 48 |
+
description_ar: Optional[str] = None
|
| 49 |
+
description_en: Optional[str] = None
|
| 50 |
+
price: float = Field(..., gt=0)
|
| 51 |
+
compare_price: Optional[float] = None
|
| 52 |
+
stock: int = Field(default=0, ge=0)
|
| 53 |
+
category_id: Optional[int] = None
|
| 54 |
+
is_featured: bool = False
|
| 55 |
+
is_active: bool = True
|
| 56 |
+
images: List[ProductImageCreate] = []
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class ProductUpdate(BaseModel):
|
| 60 |
+
name_ar: Optional[str] = None
|
| 61 |
+
name_en: Optional[str] = None
|
| 62 |
+
description_ar: Optional[str] = None
|
| 63 |
+
description_en: Optional[str] = None
|
| 64 |
+
price: Optional[float] = None
|
| 65 |
+
compare_price: Optional[float] = None
|
| 66 |
+
stock: Optional[int] = None
|
| 67 |
+
category_id: Optional[int] = None
|
| 68 |
+
is_featured: Optional[bool] = None
|
| 69 |
+
is_active: Optional[bool] = None
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class ProductListItem(BaseModel):
|
| 73 |
+
id: int
|
| 74 |
+
name_ar: str
|
| 75 |
+
name_en: str
|
| 76 |
+
price: float
|
| 77 |
+
compare_price: Optional[float] = None
|
| 78 |
+
stock: int
|
| 79 |
+
category_id: Optional[int] = None
|
| 80 |
+
category: Optional[CategoryResponse] = None
|
| 81 |
+
rating: float
|
| 82 |
+
rating_count: int
|
| 83 |
+
is_featured: bool
|
| 84 |
+
image_url: Optional[str] = None # primary image
|
| 85 |
+
created_at: datetime
|
| 86 |
+
|
| 87 |
+
model_config = {"from_attributes": True}
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
class ProductDetail(BaseModel):
|
| 91 |
+
id: int
|
| 92 |
+
name_ar: str
|
| 93 |
+
name_en: str
|
| 94 |
+
description_ar: Optional[str] = None
|
| 95 |
+
description_en: Optional[str] = None
|
| 96 |
+
price: float
|
| 97 |
+
compare_price: Optional[float] = None
|
| 98 |
+
stock: int
|
| 99 |
+
category_id: Optional[int] = None
|
| 100 |
+
category: Optional[CategoryResponse] = None
|
| 101 |
+
rating: float
|
| 102 |
+
rating_count: int
|
| 103 |
+
is_featured: bool
|
| 104 |
+
is_active: bool
|
| 105 |
+
images: List[ProductImageResponse] = []
|
| 106 |
+
created_at: datetime
|
| 107 |
+
|
| 108 |
+
model_config = {"from_attributes": True}
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# --- Pagination / Response ---
|
| 112 |
+
|
| 113 |
+
class PaginatedResponse(BaseModel):
|
| 114 |
+
isSuccess: bool = True
|
| 115 |
+
value: dict
|
| 116 |
+
statusCode: int = 200
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class ProductFilters(BaseModel):
|
| 120 |
+
search: Optional[str] = None
|
| 121 |
+
category_id: Optional[int] = None
|
| 122 |
+
min_price: Optional[float] = None
|
| 123 |
+
max_price: Optional[float] = None
|
| 124 |
+
is_featured: Optional[bool] = None
|
| 125 |
+
sort_by: str = "created_at" # created_at, price, rating, name_en
|
| 126 |
+
sort_order: str = "desc" # asc, desc
|
| 127 |
+
page: int = 1
|
| 128 |
+
page_size: int = 12
|