Add User schema
This commit is contained in:
parent
56726acd0e
commit
770eb98277
61
schemas/user.py
Normal file
61
schemas/user.py
Normal file
@ -0,0 +1,61 @@
|
||||
from pydantic import BaseModel, Field, EmailStr
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
class UserRoles(str, Enum):
|
||||
student = "student"
|
||||
teacher = "teacher"
|
||||
admin = "admin"
|
||||
|
||||
class UserBase(BaseModel):
|
||||
first_name: str = Field(..., min_length=1, max_length=50)
|
||||
last_name: str = Field(..., min_length=1, max_length=50)
|
||||
email: EmailStr = Field(..., max_length=100)
|
||||
role: UserRoles
|
||||
phone_number: str = Field(..., max_length=20)
|
||||
address: str = Field(..., max_length=200)
|
||||
date_of_birth: datetime
|
||||
profile_picture: Optional[str] = None
|
||||
is_active: bool = True
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8)
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"email": "john.doe@example.com",
|
||||
"password": "secretpass123",
|
||||
"role": "student",
|
||||
"phone_number": "+1234567890",
|
||||
"address": "123 Main St, City, Country",
|
||||
"date_of_birth": "1990-01-01T00:00:00",
|
||||
"profile_picture": "http://example.com/profile.jpg",
|
||||
"is_active": True
|
||||
}
|
||||
}
|
||||
|
||||
class UserResponse(UserBase):
|
||||
id: int
|
||||
last_login: Optional[datetime] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"id": 1,
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"email": "john.doe@example.com",
|
||||
"role": "student",
|
||||
"phone_number": "+1234567890",
|
||||
"address": "123 Main St, City, Country",
|
||||
"date_of_birth": "1990-01-01T00:00:00",
|
||||
"profile_picture": "http://example.com/profile.jpg",
|
||||
"is_active": True,
|
||||
"last_login": "2023-01-01T12:00:00"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user