Add User schema
This commit is contained in:
parent
e80b8a5410
commit
610e966de1
59
schemas/user.py
Normal file
59
schemas/user.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
from pydantic import BaseModel, Field, EmailStr
|
||||||
|
from typing import Optional
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class UserBase(BaseModel):
|
||||||
|
first_name: str = Field(..., min_length=2, max_length=50)
|
||||||
|
last_name: str = Field(..., min_length=2, max_length=50)
|
||||||
|
email: EmailStr = Field(..., description="User's email address")
|
||||||
|
role: str = Field(default="student")
|
||||||
|
grade_level: Optional[int] = Field(None)
|
||||||
|
student_id: str = Field(..., min_length=5, max_length=20)
|
||||||
|
phone_number: Optional[str] = Field(None, max_length=20)
|
||||||
|
address: Optional[str] = Field(None, max_length=200)
|
||||||
|
date_of_birth: Optional[datetime] = None
|
||||||
|
profile_picture: Optional[str] = None
|
||||||
|
|
||||||
|
class UserCreate(UserBase):
|
||||||
|
password: str = Field(..., min_length=8, max_length=100)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
schema_extra = {
|
||||||
|
"example": {
|
||||||
|
"first_name": "John",
|
||||||
|
"last_name": "Doe",
|
||||||
|
"email": "john.doe@example.com",
|
||||||
|
"password": "securepass123",
|
||||||
|
"student_id": "STU123456",
|
||||||
|
"grade_level": 10,
|
||||||
|
"phone_number": "+1234567890",
|
||||||
|
"address": "123 Main St, City, Country",
|
||||||
|
"date_of_birth": "2000-01-01T00:00:00",
|
||||||
|
"profile_picture": "https://example.com/profile.jpg"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserResponse(UserBase):
|
||||||
|
id: int
|
||||||
|
is_active: bool = True
|
||||||
|
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",
|
||||||
|
"student_id": "STU123456",
|
||||||
|
"grade_level": 10,
|
||||||
|
"phone_number": "+1234567890",
|
||||||
|
"address": "123 Main St, City, Country",
|
||||||
|
"date_of_birth": "2000-01-01T00:00:00",
|
||||||
|
"profile_picture": "https://example.com/profile.jpg",
|
||||||
|
"is_active": True,
|
||||||
|
"last_login": "2023-01-01T12:00:00"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user