updated services api
This commit is contained in:
60
ServicesApi/Validations/response/api.py
Normal file
60
ServicesApi/Validations/response/api.py
Normal file
@@ -0,0 +1,60 @@
|
||||
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,
|
||||
"data": result_data,
|
||||
"pagination": pagination_dict,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user