Add User schema
This commit is contained in:
parent
84878b5d9b
commit
99c9a183b6
@ -1,26 +1,19 @@
|
||||
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
|
||||
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 email address")
|
||||
phone: str = Field(..., min_length=10, max_length=15)
|
||||
address: Optional[str] = Field(None, max_length=200)
|
||||
city: Optional[str] = Field(None, max_length=100)
|
||||
country: Optional[str] = Field(None, max_length=100)
|
||||
is_active: bool = True
|
||||
is_admin: bool = False
|
||||
|
||||
class UserCreate(UserBase):
|
||||
password: str = Field(..., min_length=8)
|
||||
password: str = Field(..., min_length=8, max_length=100)
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
@ -28,19 +21,18 @@ class UserCreate(UserBase):
|
||||
"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
|
||||
"phone": "1234567890",
|
||||
"password": "securepass123",
|
||||
"address": "123 Main St",
|
||||
"city": "New York",
|
||||
"country": "USA",
|
||||
"is_active": True,
|
||||
"is_admin": False
|
||||
}
|
||||
}
|
||||
|
||||
class UserResponse(UserBase):
|
||||
id: int
|
||||
last_login: Optional[datetime] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
@ -50,12 +42,11 @@ class UserResponse(UserBase):
|
||||
"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",
|
||||
"phone": "1234567890",
|
||||
"address": "123 Main St",
|
||||
"city": "New York",
|
||||
"country": "USA",
|
||||
"is_active": True,
|
||||
"last_login": "2023-01-01T12:00:00"
|
||||
"is_admin": False
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user