created design pattern
This commit is contained in:
@@ -144,6 +144,7 @@ class Pagination:
|
||||
self.orderField = "uu_id"
|
||||
self.orderType = "asc"
|
||||
|
||||
@property
|
||||
def as_dict(self) -> Dict[str, Any]:
|
||||
"""Convert pagination state to dictionary format."""
|
||||
self.refresh()
|
||||
|
||||
@@ -112,6 +112,8 @@ class PostgresResponse(Generic[T]):
|
||||
|
||||
|
||||
class EndpointResponse(BaseModel):
|
||||
"""Endpoint response model."""
|
||||
|
||||
completed: bool = True
|
||||
message: str = "Success"
|
||||
pagination_result: Any
|
||||
@@ -119,9 +121,18 @@ class EndpointResponse(BaseModel):
|
||||
@property
|
||||
def response(self):
|
||||
"""Convert response to dictionary format."""
|
||||
resutl_data = getattr(self.pagination_result, "data", None)
|
||||
if not resutl_data:
|
||||
raise ValueError("Invalid pagination result data.")
|
||||
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,
|
||||
"data": self.pagination_result.data,
|
||||
"pagination": self.pagination_result.pagination.as_dict(),
|
||||
"data": resutl_data,
|
||||
"pagination": pagination_dict,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user