Spaces:
Sleeping
Sleeping
| from pydantic import BaseModel, EmailStr, Field, validator | |
| from datetime import datetime, date | |
| from typing import Optional, Dict, Any | |
| import re | |
| class ProfileUpdateRequest(BaseModel): | |
| """Request model for updating user profile""" | |
| name: Optional[str] = Field(None, min_length=2, max_length=100, description="User's full name") | |
| email: Optional[EmailStr] = Field(None, description="User's email address") | |
| phone: Optional[str] = Field(None, description="User's phone number") | |
| date_of_birth: Optional[str] = Field(None, description="Date of birth in DD/MM/YYYY format") | |
| profile_picture: Optional[str] = Field(None, description="Profile picture URL") | |
| def validate_phone(cls, v): | |
| if v is not None: | |
| # Remove any non-digit characters | |
| phone_digits = re.sub(r'\D', '', v) | |
| if len(phone_digits) != 10: | |
| raise ValueError('Phone number must be exactly 10 digits') | |
| return phone_digits | |
| return v | |
| def validate_date_of_birth(cls, v): | |
| if v is not None: | |
| try: | |
| # Parse DD/MM/YYYY format | |
| day, month, year = map(int, v.split('/')) | |
| birth_date = date(year, month, day) | |
| # Check if date is not in the future | |
| if birth_date > date.today(): | |
| raise ValueError('Date of birth cannot be in the future') | |
| # Check if age is reasonable (not more than 120 years) | |
| age = (date.today() - birth_date).days // 365 | |
| if age > 120: | |
| raise ValueError('Invalid date of birth') | |
| return v | |
| except ValueError as e: | |
| if "Invalid date of birth" in str(e) or "Date of birth cannot be in the future" in str(e): | |
| raise e | |
| raise ValueError('Date of birth must be in DD/MM/YYYY format') | |
| return v | |
| class ProfileResponse(BaseModel): | |
| """Response model for user profile""" | |
| customer_id: str = Field(..., description="Unique user identifier") | |
| name: str = Field(..., description="User's full name") | |
| email: Optional[str] = Field(None, description="User's email address") | |
| phone: Optional[str] = Field(None, description="User's phone number") | |
| date_of_birth: Optional[str] = Field(None, description="Date of birth in DD/MM/YYYY format") | |
| profile_picture: Optional[str] = Field(None, description="Profile picture URL") | |
| auth_method: str = Field(..., description="Authentication method used") | |
| created_at: datetime = Field(..., description="Account creation timestamp") | |
| updated_at: Optional[datetime] = Field(None, description="Last profile update timestamp") | |
| class Config: | |
| from_attributes = True | |
| class PersonalDetailsResponse(BaseModel): | |
| """Response model for personal details section""" | |
| first_name: str = Field(..., description="User's first name") | |
| last_name: str = Field(..., description="User's last name") | |
| email: str = Field(..., description="User's email address") | |
| phone: str = Field(..., description="User's phone number") | |
| date_of_birth: Optional[str] = Field(None, description="Date of birth in DD/MM/YYYY format") | |
| class Config: | |
| from_attributes = True | |
| class ProfileOperationResponse(BaseModel): | |
| """Response model for profile operations""" | |
| success: bool = Field(..., description="Operation success status") | |
| message: str = Field(..., description="Response message") | |
| profile: Optional[ProfileResponse] = Field(None, description="Updated profile data") | |
| class WalletDisplayResponse(BaseModel): | |
| """Response model for wallet display in profile""" | |
| balance: float = Field(..., description="Current wallet balance") | |
| formatted_balance: str = Field(..., description="Formatted balance with currency symbol") | |
| currency: str = Field(default="INR", description="Currency code") | |
| class ProfileDashboardResponse(BaseModel): | |
| """Complete response model for profile dashboard""" | |
| personal_details: PersonalDetailsResponse = Field(..., description="Personal details") | |
| wallet: WalletDisplayResponse = Field(..., description="Wallet information") | |
| address_count: int = Field(..., description="Number of saved addresses") | |
| has_default_address: bool = Field(..., description="Whether user has a default address set") |