From f568b2b5ce4d98a2c6cf0499b7f4a3a00d0af3d8 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Thu, 4 Jun 2026 00:06:23 +0000 Subject: [PATCH] Upload app/schemas/user.py --- app/schemas/user.py | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 app/schemas/user.py diff --git a/app/schemas/user.py b/app/schemas/user.py new file mode 100644 index 0000000..56bd139 --- /dev/null +++ b/app/schemas/user.py @@ -0,0 +1,56 @@ +"""Pydantic schemas for User endpoints.""" + +from __future__ import annotations + +from datetime import datetime +from typing import Optional + +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 + avatar_url: Optional[str] = None + email_notifications: bool = True + created_at: datetime + + +class UserUpdate(BaseModel): + """Request body for PATCH /api/v1/users/{id} (admin or self).""" + + name: Optional[str] = Field(None, min_length=1, max_length=255) + avatar_url: Optional[str] = Field(None, max_length=1024) + email_notifications: Optional[bool] = None + role: Optional[UserRole] = None # admin-only + + +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"]