34 lines
961 B
Python
34 lines
961 B
Python
# app/schemas/user.py
|
|
from pydantic import BaseModel, EmailStr, ConfigDict
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
# Shared properties
|
|
class UserBase(BaseModel):
|
|
email: EmailStr
|
|
name: Optional[str] = None
|
|
|
|
# Properties to receive via API on creation
|
|
class UserCreate(UserBase):
|
|
password: str
|
|
|
|
# Properties to receive via API on update (optional, add later if needed)
|
|
# class UserUpdate(UserBase):
|
|
# password: Optional[str] = None
|
|
|
|
# Properties stored in DB
|
|
class UserInDBBase(UserBase):
|
|
id: int
|
|
hashed_password: str
|
|
created_at: datetime
|
|
model_config = ConfigDict(from_attributes=True) # Use orm_mode in Pydantic v1
|
|
|
|
# Additional properties to return via API (excluding password)
|
|
class UserPublic(UserBase):
|
|
id: int
|
|
created_at: datetime
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
# Full user model including hashed password (for internal use/reading from DB)
|
|
class User(UserInDBBase):
|
|
pass |