From 770eb98277791c407b2bbaa556ab2e314934328c Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Thu, 27 Mar 2025 21:15:42 +0000 Subject: [PATCH] Add User schema --- schemas/user.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 schemas/user.py diff --git a/schemas/user.py b/schemas/user.py new file mode 100644 index 0000000..77c1252 --- /dev/null +++ b/schemas/user.py @@ -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" + } + } \ No newline at end of file