updated last web service

This commit is contained in:
2025-06-02 21:11:15 +03:00
parent df3f59bd8e
commit 0cd0eb0f22
106 changed files with 1061 additions and 50 deletions

View File

@@ -31,8 +31,8 @@ class EndpointResponse(BaseModel):
return {
"completed": self.completed,
"message": self.message,
"data": result_data,
"pagination": pagination_dict,
"data": result_data,
}
model_config = {

View File

@@ -26,7 +26,8 @@ class Pagination:
MIN_SIZE = default_paginate_config.MIN_SIZE
MAX_SIZE = default_paginate_config.MAX_SIZE
def __init__(self, data: PostgresResponse):
def __init__(self, data: Query, base_query: Query):
self.base_query = base_query
self.query = data
self.size: int = self.DEFAULT_SIZE
self.page: int = 1
@@ -60,7 +61,7 @@ class Pagination:
"""Update page counts and validate current page."""
if self.query:
self.total_count = self.query.count()
self.all_count = self.query.count()
self.all_count = self.base_query.count()
self.size = (
self.size
@@ -151,24 +152,14 @@ class PaginationResult:
Ordered query object.
"""
if not len(self.order_by) == len(self.pagination.orderType):
raise ValueError(
"Order by fields and order types must have the same length."
)
raise ValueError("Order by fields and order types must have the same length.")
order_criteria = zip(self.order_by, self.pagination.orderType)
for field, direction in order_criteria:
if hasattr(self._query.column_descriptions[0]["entity"], field):
if direction.lower().startswith("d"):
self._query = self._query.order_by(
desc(
getattr(self._query.column_descriptions[0]["entity"], field)
)
)
self._query = self._query.order_by(desc(getattr(self._query.column_descriptions[0]["entity"], field)))
else:
self._query = self._query.order_by(
asc(
getattr(self._query.column_descriptions[0]["entity"], field)
)
)
self._query = self._query.order_by(asc(getattr(self._query.column_descriptions[0]["entity"], field)))
return self._query
@property