2026-06-03 20:52:01 +00:00
|
|
|
"""Pydantic schemas for User endpoints."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
from pydantic import BaseModel, ConfigDict, EmailStr, Field
|
|
|
|
|
|
|
|
|
|
from app.models.user import UserRole
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserOut(BaseModel):
|
|
|
|
|
"""Response schema for a user (never includes password_hash)."""
|
|
|
|
|
|
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
|
|
|
|
id: int
|
|
|
|
|
email: EmailStr
|
|
|
|
|
name: str
|
|
|
|
|
role: UserRole
|
|
|
|
|
org_id: int
|
2026-06-10 20:52:56 +00:00
|
|
|
avatar_url: str | None = None
|
2026-06-03 20:52:01 +00:00
|
|
|
email_notifications: bool = True
|
|
|
|
|
created_at: datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserUpdate(BaseModel):
|
|
|
|
|
"""Request body for PATCH /api/v1/users/{id} (admin or self)."""
|
|
|
|
|
|
2026-06-10 20:52:56 +00:00
|
|
|
name: str | None = Field(None, min_length=1, max_length=255)
|
|
|
|
|
avatar_url: str | None = Field(None, max_length=1024)
|
|
|
|
|
email_notifications: bool | None = None
|
|
|
|
|
role: UserRole | None = None # admin-only
|
2026-06-03 20:52:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserCreateRequest(BaseModel):
|
|
|
|
|
"""Request body for POST /api/v1/users (admin-only)."""
|
|
|
|
|
|
|
|
|
|
email: EmailStr
|
|
|
|
|
password: str = Field(..., min_length=8, max_length=128)
|
|
|
|
|
name: str = Field(..., min_length=1, max_length=255)
|
|
|
|
|
role: UserRole = UserRole.sales_rep
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserListResponse(BaseModel):
|
|
|
|
|
"""Response schema for paginated user list."""
|
|
|
|
|
|
|
|
|
|
items: list[UserOut]
|
|
|
|
|
total: int
|
|
|
|
|
page: int
|
|
|
|
|
page_size: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Re-export for late import in auth.py
|
|
|
|
|
__all__ = ["UserCreateRequest", "UserListResponse", "UserOut", "UserUpdate"]
|