29 lines
554 B
Python
29 lines
554 B
Python
from __future__ import annotations
|
|
|
|
from datetime import datetime, timezone
|
|
from typing import Generic, TypeVar
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class ApiResponse(BaseModel, Generic[T]):
|
|
code: int = 200
|
|
message: str = "success"
|
|
data: T | None = None
|
|
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|
|
|
|
|
|
class Pagination(BaseModel):
|
|
page: int
|
|
limit: int
|
|
total: int
|
|
pages: int
|
|
|
|
|
|
class PageResponse(BaseModel, Generic[T]):
|
|
items: list[T]
|
|
pagination: Pagination
|