Add User schema
This commit is contained in:
parent
84878b5d9b
commit
99c9a183b6
@ -1,26 +1,19 @@
|
|||||||
from pydantic import BaseModel, Field, EmailStr
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
from enum import Enum
|
|
||||||
from datetime import datetime
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
class UserRoles(str, Enum):
|
|
||||||
student = "student"
|
|
||||||
teacher = "teacher"
|
|
||||||
admin = "admin"
|
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
first_name: str = Field(..., min_length=1, max_length=50)
|
first_name: str = Field(..., min_length=2, max_length=50)
|
||||||
last_name: str = Field(..., min_length=1, max_length=50)
|
last_name: str = Field(..., min_length=2, max_length=50)
|
||||||
email: EmailStr = Field(..., max_length=100)
|
email: EmailStr = Field(..., description="User email address")
|
||||||
role: UserRoles
|
phone: str = Field(..., min_length=10, max_length=15)
|
||||||
phone_number: str = Field(..., max_length=20)
|
address: Optional[str] = Field(None, max_length=200)
|
||||||
address: str = Field(..., max_length=200)
|
city: Optional[str] = Field(None, max_length=100)
|
||||||
date_of_birth: datetime
|
country: Optional[str] = Field(None, max_length=100)
|
||||||
profile_picture: Optional[str] = None
|
|
||||||
is_active: bool = True
|
is_active: bool = True
|
||||||
|
is_admin: bool = False
|
||||||
|
|
||||||
class UserCreate(UserBase):
|
class UserCreate(UserBase):
|
||||||
password: str = Field(..., min_length=8)
|
password: str = Field(..., min_length=8, max_length=100)
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
schema_extra = {
|
schema_extra = {
|
||||||
@ -28,19 +21,18 @@ class UserCreate(UserBase):
|
|||||||
"first_name": "John",
|
"first_name": "John",
|
||||||
"last_name": "Doe",
|
"last_name": "Doe",
|
||||||
"email": "john.doe@example.com",
|
"email": "john.doe@example.com",
|
||||||
"password": "secretpass123",
|
"phone": "1234567890",
|
||||||
"role": "student",
|
"password": "securepass123",
|
||||||
"phone_number": "+1234567890",
|
"address": "123 Main St",
|
||||||
"address": "123 Main St, City, Country",
|
"city": "New York",
|
||||||
"date_of_birth": "1990-01-01T00:00:00",
|
"country": "USA",
|
||||||
"profile_picture": "http://example.com/profile.jpg",
|
"is_active": True,
|
||||||
"is_active": True
|
"is_admin": False
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class UserResponse(UserBase):
|
class UserResponse(UserBase):
|
||||||
id: int
|
id: int
|
||||||
last_login: Optional[datetime] = None
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
orm_mode = True
|
orm_mode = True
|
||||||
@ -50,12 +42,11 @@ class UserResponse(UserBase):
|
|||||||
"first_name": "John",
|
"first_name": "John",
|
||||||
"last_name": "Doe",
|
"last_name": "Doe",
|
||||||
"email": "john.doe@example.com",
|
"email": "john.doe@example.com",
|
||||||
"role": "student",
|
"phone": "1234567890",
|
||||||
"phone_number": "+1234567890",
|
"address": "123 Main St",
|
||||||
"address": "123 Main St, City, Country",
|
"city": "New York",
|
||||||
"date_of_birth": "1990-01-01T00:00:00",
|
"country": "USA",
|
||||||
"profile_picture": "http://example.com/profile.jpg",
|
|
||||||
"is_active": True,
|
"is_active": True,
|
||||||
"last_login": "2023-01-01T12:00:00"
|
"is_admin": False
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user