60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from .result import PaginationResult
|
|
from .base import PostgresResponseSingle
|
|
from pydantic import BaseModel
|
|
from typing import Any, Type
|
|
|
|
|
|
class EndpointResponse(BaseModel):
|
|
"""Endpoint response model."""
|
|
|
|
completed: bool = True
|
|
message: str = "Success"
|
|
pagination_result: PaginationResult
|
|
|
|
@property
|
|
def response(self):
|
|
"""Convert response to dictionary format."""
|
|
result_data = getattr(self.pagination_result, "data", None)
|
|
if not result_data:
|
|
return {
|
|
"completed": False,
|
|
"message": "MSG0004-NODATA",
|
|
"data": None,
|
|
"pagination": None,
|
|
}
|
|
result_pagination = getattr(self.pagination_result, "pagination", None)
|
|
if not result_pagination:
|
|
raise ValueError("Invalid pagination result pagination.")
|
|
pagination_dict = getattr(result_pagination, "as_dict", None)
|
|
if not pagination_dict:
|
|
raise ValueError("Invalid pagination result as_dict.")
|
|
return {
|
|
"completed": self.completed,
|
|
"message": self.message,
|
|
"pagination": pagination_dict,
|
|
"data": result_data,
|
|
}
|
|
|
|
model_config = {
|
|
"arbitrary_types_allowed": True
|
|
}
|
|
|
|
class CreateEndpointResponse(BaseModel):
|
|
"""Create endpoint response model."""
|
|
|
|
completed: bool = True
|
|
message: str = "Success"
|
|
data: PostgresResponseSingle
|
|
|
|
@property
|
|
def response(self):
|
|
"""Convert response to dictionary format."""
|
|
return {
|
|
"completed": self.completed,
|
|
"message": self.message,
|
|
"data": self.data.data,
|
|
}
|
|
|
|
model_config = {
|
|
"arbitrary_types_allowed": True
|
|
} |