Files
forms/app/schemas/common.py
2026-04-09 19:28:41 +03:00

45 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from pydantic import BaseModel, Field
from typing import Optional, Generic, TypeVar, List
from datetime import datetime
T = TypeVar('T')
class BaseSchema(BaseModel):
"""Базовый класс для всех схем"""
class Config:
from_attributes = True
json_encoders = {
datetime: lambda v: v.isoformat()
}
class PaginationParams(BaseModel):
"""Параметры пагинации"""
page: int = Field(1, ge=1, description="Номер страницы")
per_page: int = Field(20, ge=1, le=100, description="Записей на странице")
order_by: Optional[str] = Field(None, description="Поле для сортировки")
descending: bool = Field(True, description="По убыванию")
class PaginatedResponse(BaseSchema, Generic[T]):
"""Ответ с пагинацией"""
items: List[T]
total: int
page: int
per_page: int
pages: int
class MessageResponse(BaseSchema):
"""Простой ответ с сообщением"""
message: str
success: bool = True
class ErrorResponse(BaseSchema):
"""Ответ с ошибкой"""
error: str
detail: Optional[str] = None
status_code: int