Add User schema
This commit is contained in:
parent
4852ff3f12
commit
959de7403d
@ -1,34 +1,58 @@
|
|||||||
from pydantic import BaseModel, Field, EmailStr
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
name: str = Field(..., min_length=1, max_length=100, description="User's full name")
|
username: str = Field(..., min_length=3, max_length=50)
|
||||||
address: str = Field(..., min_length=1, max_length=200, description="User's address")
|
email: EmailStr = Field(...)
|
||||||
phone: Optional[str] = Field(None, max_length=20, description="User's phone number")
|
first_name: Optional[str] = Field(None, max_length=50)
|
||||||
email: EmailStr = Field(..., description="User's email address")
|
last_name: Optional[str] = Field(None, max_length=50)
|
||||||
is_active: bool = Field(default=True, description="User's active status")
|
bio: Optional[str] = Field(None, max_length=500)
|
||||||
|
profile_picture: Optional[str] = Field(None)
|
||||||
|
relationship_status: Optional[str] = Field(None)
|
||||||
|
interests: Optional[str] = Field(None, max_length=500)
|
||||||
|
is_active: bool = Field(default=True)
|
||||||
|
|
||||||
class UserCreate(UserBase):
|
class UserCreate(UserBase):
|
||||||
|
password: str = Field(..., min_length=8, max_length=100)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
"example": {
|
"example": {
|
||||||
"name": "John Doe",
|
"username": "johndoe",
|
||||||
"address": "123 Main St, City, Country",
|
|
||||||
"phone": "+1234567890",
|
|
||||||
"email": "john@example.com",
|
"email": "john@example.com",
|
||||||
"is_active": True
|
"password": "securepass123",
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"bio": "Hello, I'm John!",
|
||||||
|
"profile_picture": "https://example.com/picture.jpg",
|
||||||
|
"relationship_status": "single",
|
||||||
|
"interests": "Reading, hiking, photography"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserResponse(UserBase):
|
class UserResponse(UserBase):
|
||||||
|
id: int
|
||||||
|
last_login: Optional[datetime]
|
||||||
|
created_at: datetime
|
||||||
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
"example": {
|
"example": {
|
||||||
"name": "John Doe",
|
"id": 1,
|
||||||
"address": "123 Main St, City, Country",
|
"username": "johndoe",
|
||||||
"phone": "+1234567890",
|
|
||||||
"email": "john@example.com",
|
"email": "john@example.com",
|
||||||
"is_active": True
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"bio": "Hello, I'm John!",
|
||||||
|
"profile_picture": "https://example.com/picture.jpg",
|
||||||
|
"relationship_status": "single",
|
||||||
|
"interests": "Reading, hiking, photography",
|
||||||
|
"is_active": True,
|
||||||
|
"last_login": "2023-01-01T12:00:00",
|
||||||
|
"created_at": "2023-01-01T10:00:00",
|
||||||
|
"updated_at": "2023-01-01T10:00:00"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user