23 lines
527 B
Python
23 lines
527 B
Python
from pydantic import BaseModel
|
|
from typing import Generic, TypeVar, Optional
|
|
|
|
T = TypeVar("T")
|
|
|
|
|
|
class ApiResponse(BaseModel, Generic[T]):
|
|
success: bool
|
|
message: str
|
|
data: Optional[T] = None
|
|
|
|
def to_json(self) -> str:
|
|
"""
|
|
Convert the model to a properly formatted JSON string.
|
|
"""
|
|
return self.model_dump_json(indent=4)
|
|
|
|
def to_dict(self) -> dict:
|
|
"""
|
|
Convert the model to a dictionary with proper key-value pairs.
|
|
"""
|
|
return self.model_dump()
|