123
This commit is contained in:
0
backend/auth_service/app/schemas/__init__.py
Normal file
0
backend/auth_service/app/schemas/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
57
backend/auth_service/app/schemas/user.py
Normal file
57
backend/auth_service/app/schemas/user.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
Pydantic schemas for User-related data structures
|
||||
Defines request/response models for authentication endpoints
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, EmailStr, Field
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
class UserBase(BaseModel):
|
||||
"""Base schema for user data"""
|
||||
username: str = Field(..., min_length=3, max_length=50, description="Unique username")
|
||||
email: EmailStr = Field(..., description="Valid email address")
|
||||
|
||||
class UserCreate(UserBase):
|
||||
"""Schema for user registration request"""
|
||||
password: str = Field(..., min_length=8, description="Password (min 8 characters)")
|
||||
|
||||
class UserLogin(BaseModel):
|
||||
"""Schema for user login request"""
|
||||
email: EmailStr = Field(..., description="User's email address")
|
||||
password: str = Field(..., description="User's password")
|
||||
|
||||
class UserUpdate(BaseModel):
|
||||
"""Schema for user profile updates"""
|
||||
username: Optional[str] = Field(None, min_length=3, max_length=50)
|
||||
email: Optional[EmailStr] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
class UserResponse(UserBase):
|
||||
"""Schema for user response data"""
|
||||
id: UUID
|
||||
created_at: datetime
|
||||
is_active: bool
|
||||
|
||||
class Config:
|
||||
from_attributes = True # Enable ORM mode
|
||||
|
||||
class Token(BaseModel):
|
||||
"""Schema for JWT token response (login / refresh)"""
|
||||
access_token: str = Field(..., description="JWT access token")
|
||||
refresh_token: str = Field(..., description="Opaque refresh token")
|
||||
token_type: str = Field(default="bearer", description="Token type")
|
||||
expires_in: int = Field(..., description="Access token expiration time in seconds")
|
||||
|
||||
|
||||
class RefreshTokenRequest(BaseModel):
|
||||
"""Schema for token refresh request"""
|
||||
refresh_token: str = Field(..., description="The refresh token to exchange")
|
||||
|
||||
|
||||
class TokenData(BaseModel):
|
||||
"""Schema for decoded token payload"""
|
||||
sub: str = Field(..., description="Subject (user ID)")
|
||||
username: str = Field(..., description="Username")
|
||||
exp: Optional[int] = None
|
||||
Reference in New Issue
Block a user