- Add promo preference fields to User model (promo_preferred_maker, promo_preferred_model, promo_email_enabled) - Create API endpoints for getting/updating promo preferences - Create PromoPreference component with maker/model selection - Show login prompt for non-logged-in users when interacting - Add promo notification service to send emails when matching vehicles are added to promotion - Add multi-language translations (en, mn, ru, ko) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
92 lines
2.3 KiB
Python
92 lines
2.3 KiB
Python
from pydantic import BaseModel, EmailStr, field_validator
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
import re
|
|
|
|
|
|
class UserCreate(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
name: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
country: str = "Mongolia"
|
|
referred_by: Optional[str] = None # Referral code of the user who referred
|
|
|
|
@field_validator('password')
|
|
@classmethod
|
|
def validate_password(cls, v):
|
|
if len(v) < 10:
|
|
raise ValueError('Password must be at least 10 characters long')
|
|
if not re.search(r'[!@#$%^&*(),.?":{}|<>_\-+=\[\]\\\/`~]', v):
|
|
raise ValueError('Password must contain at least one special character')
|
|
return v
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
"""Schema for updating user profile"""
|
|
name: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
country: Optional[str] = None
|
|
|
|
|
|
class UserResponse(BaseModel):
|
|
id: int
|
|
email: str
|
|
name: Optional[str] = None
|
|
phone: Optional[str] = None
|
|
country: str
|
|
is_active: bool
|
|
is_admin: bool = False
|
|
is_dealer: bool = False
|
|
cc_balance: float = 0.0 # Float to support fractional CC (e.g., 0.1 CC)
|
|
referral_code: Optional[str] = None # User's unique referral code
|
|
email_verified: bool = False
|
|
phone_verified: bool = False
|
|
promo_preferred_maker: Optional[str] = None
|
|
promo_preferred_model: Optional[str] = None
|
|
promo_email_enabled: bool = False
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PromoPreferenceUpdate(BaseModel):
|
|
"""Schema for updating promo preference"""
|
|
promo_preferred_maker: Optional[str] = None
|
|
promo_preferred_model: Optional[str] = None
|
|
promo_email_enabled: bool = False
|
|
|
|
|
|
class PromoPreferenceResponse(BaseModel):
|
|
promo_preferred_maker: Optional[str] = None
|
|
promo_preferred_model: Optional[str] = None
|
|
promo_email_enabled: bool = False
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class CarViewResponse(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
car_id: int
|
|
cc_paid: int
|
|
created_at: datetime
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PurchaseViewRequest(BaseModel):
|
|
car_id: int
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str = "bearer"
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
email: Optional[str] = None
|