Add User schema
This commit is contained in:
parent
80e856b19d
commit
136fb33832
@ -1,25 +1,45 @@
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
from datetime import datetime
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
name: Optional[str] = Field(None, min_length=1, max_length=100, description="User's name")
|
username: str = Field(..., min_length=3, max_length=50)
|
||||||
|
email: EmailStr = Field(..., description="User's email address")
|
||||||
|
first_name: Optional[str] = Field(None, max_length=50)
|
||||||
|
last_name: Optional[str] = Field(None, max_length=50)
|
||||||
|
|
||||||
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",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"password": "securepass123"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class User(UserBase):
|
class User(UserBase):
|
||||||
id: int
|
id: UUID
|
||||||
|
is_active: bool = Field(default=True)
|
||||||
|
created_at: datetime
|
||||||
|
updated_at: datetime
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
"example": {
|
"example": {
|
||||||
"id": 1,
|
"id": "550e8400-e29b-41d4-a716-446655440000",
|
||||||
"name": "John Doe"
|
"username": "johndoe",
|
||||||
|
"email": "john@example.com",
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"is_active": True,
|
||||||
|
"created_at": "2023-01-01T00:00:00",
|
||||||
|
"updated_at": "2023-01-01T00:00:00"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user