77 lines
2.2 KiB
Python
77 lines
2.2 KiB
Python
from pydantic import BaseModel, EmailStr, Field, field_validator
|
|
from typing import Optional
|
|
from datetime import date
|
|
from uuid import UUID
|
|
|
|
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
phone: Optional[str] = None
|
|
first_name: str = Field(..., min_length=1, max_length=50)
|
|
last_name: str = Field(..., min_length=1, max_length=50)
|
|
date_of_birth: Optional[date] = None
|
|
bio: Optional[str] = Field(None, max_length=500)
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
password: str = Field(..., min_length=8, max_length=100)
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
first_name: Optional[str] = Field(None, min_length=1, max_length=50)
|
|
last_name: Optional[str] = Field(None, min_length=1, max_length=50)
|
|
phone: Optional[str] = None
|
|
date_of_birth: Optional[date] = None
|
|
bio: Optional[str] = Field(None, max_length=500)
|
|
avatar_url: Optional[str] = None
|
|
|
|
# Emergency contacts
|
|
emergency_contact_1_name: Optional[str] = Field(None, max_length=100)
|
|
emergency_contact_1_phone: Optional[str] = Field(None, max_length=20)
|
|
emergency_contact_2_name: Optional[str] = Field(None, max_length=100)
|
|
emergency_contact_2_phone: Optional[str] = Field(None, max_length=20)
|
|
|
|
# Settings
|
|
location_sharing_enabled: Optional[bool] = None
|
|
emergency_notifications_enabled: Optional[bool] = None
|
|
push_notifications_enabled: Optional[bool] = None
|
|
|
|
|
|
class UserResponse(UserBase):
|
|
id: int
|
|
uuid: str
|
|
avatar_url: Optional[str] = None
|
|
emergency_contact_1_name: Optional[str] = None
|
|
emergency_contact_1_phone: Optional[str] = None
|
|
emergency_contact_2_name: Optional[str] = None
|
|
emergency_contact_2_phone: Optional[str] = None
|
|
location_sharing_enabled: bool
|
|
emergency_notifications_enabled: bool
|
|
push_notifications_enabled: bool
|
|
email_verified: bool
|
|
phone_verified: bool
|
|
is_active: bool
|
|
|
|
@field_validator('uuid', mode='before')
|
|
@classmethod
|
|
def convert_uuid_to_str(cls, v):
|
|
if isinstance(v, UUID):
|
|
return str(v)
|
|
return v
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class UserLogin(BaseModel):
|
|
email: EmailStr
|
|
password: str
|
|
|
|
|
|
class Token(BaseModel):
|
|
access_token: str
|
|
token_type: str
|
|
|
|
|
|
class TokenData(BaseModel):
|
|
email: Optional[str] = None |