mirror of
http://88.130.71.182:3000/BlitTech/badoHair_be.git
synced 2026-06-13 10:19:20 +00:00
43 lines
886 B
Python
43 lines
886 B
Python
from typing import Any, TypeVar, Generic
|
|
from pydantic import BaseModel
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class ErrorDetail(BaseModel):
|
|
code: str
|
|
message: str
|
|
details: Any = None
|
|
|
|
|
|
class APIResponse(BaseModel, Generic[T]):
|
|
success: bool
|
|
data: T | None = None
|
|
error: ErrorDetail | None = None
|
|
|
|
|
|
class PaginationMeta(BaseModel):
|
|
total: int
|
|
page: int
|
|
per_page: int
|
|
pages: int
|
|
|
|
|
|
class PaginatedAPIResponse(BaseModel, Generic[T]):
|
|
success: bool = True
|
|
data: list[T] = []
|
|
meta: PaginationMeta
|
|
|
|
|
|
def ok(data: Any = None) -> dict:
|
|
return {"success": True, "data": data}
|
|
|
|
|
|
def paginated(data: list, total: int, page: int, per_page: int) -> dict:
|
|
pages = max(1, (total + per_page - 1) // per_page)
|
|
return {
|
|
"success": True,
|
|
"data": data,
|
|
"meta": {"total": total, "page": page, "per_page": per_page, "pages": pages},
|
|
}
|