129 lines
3.9 KiB
Python
129 lines
3.9 KiB
Python
import re
|
|
from datetime import datetime
|
|
from typing import List, Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
|
|
|
|
from models.api.product import ProductResponse
|
|
|
|
|
|
class ShopCreate(BaseModel):
|
|
shop_code: str = Field(
|
|
...,
|
|
min_length=3,
|
|
max_length=50,
|
|
description="Unique shop code (e.g., TECHSTORE)",
|
|
)
|
|
shop_name: str = Field(
|
|
..., min_length=1, max_length=200, description="Display name of the shop"
|
|
)
|
|
description: Optional[str] = Field(
|
|
None, max_length=2000, description="Shop description"
|
|
)
|
|
contact_email: Optional[str] = None
|
|
contact_phone: Optional[str] = None
|
|
website: Optional[str] = None
|
|
business_address: Optional[str] = None
|
|
tax_number: Optional[str] = None
|
|
|
|
@field_validator("shop_code")
|
|
def validate_shop_code(cls, v):
|
|
# Convert to uppercase and check format
|
|
v = v.upper().strip()
|
|
if not v.replace("_", "").replace("-", "").isalnum():
|
|
raise ValueError(
|
|
"Shop code must be alphanumeric (underscores and hyphens allowed)"
|
|
)
|
|
return v
|
|
|
|
@field_validator("contact_email")
|
|
def validate_contact_email(cls, v):
|
|
if v and ("@" not in v or "." not in v):
|
|
raise ValueError("Invalid email format")
|
|
return v.lower() if v else v
|
|
|
|
|
|
class ShopUpdate(BaseModel):
|
|
shop_name: Optional[str] = Field(None, min_length=1, max_length=200)
|
|
description: Optional[str] = Field(None, max_length=2000)
|
|
contact_email: Optional[str] = None
|
|
contact_phone: Optional[str] = None
|
|
website: Optional[str] = None
|
|
business_address: Optional[str] = None
|
|
tax_number: Optional[str] = None
|
|
|
|
@field_validator("contact_email")
|
|
def validate_contact_email(cls, v):
|
|
if v and ("@" not in v or "." not in v):
|
|
raise ValueError("Invalid email format")
|
|
return v.lower() if v else v
|
|
|
|
|
|
class ShopResponse(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
shop_code: str
|
|
shop_name: str
|
|
description: Optional[str]
|
|
owner_id: int
|
|
contact_email: Optional[str]
|
|
contact_phone: Optional[str]
|
|
website: Optional[str]
|
|
business_address: Optional[str]
|
|
tax_number: Optional[str]
|
|
is_active: bool
|
|
is_verified: bool
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
|
|
|
|
class ShopListResponse(BaseModel):
|
|
shops: List[ShopResponse]
|
|
total: int
|
|
skip: int
|
|
limit: int
|
|
|
|
|
|
class ShopProductCreate(BaseModel):
|
|
product_id: str = Field(..., description="Product ID to add to shop")
|
|
shop_product_id: Optional[str] = Field(
|
|
None, description="Shop's internal product ID"
|
|
)
|
|
shop_price: Optional[float] = Field(
|
|
None, ge=0, description="Shop-specific price override"
|
|
)
|
|
shop_sale_price: Optional[float] = Field(
|
|
None, ge=0, description="Shop-specific sale price"
|
|
)
|
|
shop_currency: Optional[str] = Field(None, description="Shop-specific currency")
|
|
shop_availability: Optional[str] = Field(
|
|
None, description="Shop-specific availability"
|
|
)
|
|
shop_condition: Optional[str] = Field(None, description="Shop-specific condition")
|
|
is_featured: bool = Field(False, description="Featured product flag")
|
|
min_quantity: int = Field(1, ge=1, description="Minimum order quantity")
|
|
max_quantity: Optional[int] = Field(
|
|
None, ge=1, description="Maximum order quantity"
|
|
)
|
|
|
|
|
|
class ShopProductResponse(BaseModel):
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
id: int
|
|
shop_id: int
|
|
product: ProductResponse
|
|
shop_product_id: Optional[str]
|
|
shop_price: Optional[float]
|
|
shop_sale_price: Optional[float]
|
|
shop_currency: Optional[str]
|
|
shop_availability: Optional[str]
|
|
shop_condition: Optional[str]
|
|
is_featured: bool
|
|
is_active: bool
|
|
min_quantity: int
|
|
max_quantity: Optional[int]
|
|
created_at: datetime
|
|
updated_at: datetime
|