updated list options and response validatore tested
This commit is contained in:
@@ -136,13 +136,14 @@ class PaginationResult:
|
||||
pagination: Pagination state
|
||||
"""
|
||||
|
||||
def __init__(self, data: PostgresResponse, pagination: Pagination):
|
||||
def __init__(self, data: PostgresResponse, pagination: Pagination, response_model: Any = None):
|
||||
self._query = data.query
|
||||
self.pagination = pagination
|
||||
self.response_type = data.is_list
|
||||
self.limit = self.pagination.size
|
||||
self.offset = self.pagination.size * (self.pagination.page - 1)
|
||||
self.order_by = self.pagination.orderField
|
||||
self.response_model = response_model
|
||||
|
||||
def dynamic_order_by(self):
|
||||
"""
|
||||
@@ -179,11 +180,14 @@ class PaginationResult:
|
||||
queried_data = (
|
||||
query_paginated.all() if self.response_type else query_paginated.first()
|
||||
)
|
||||
return (
|
||||
data = (
|
||||
[result.get_dict() for result in queried_data]
|
||||
if self.response_type
|
||||
else queried_data.get_dict()
|
||||
)
|
||||
if self.response_model:
|
||||
return [self.response_model(**item).model_dump() for item in data]
|
||||
return data
|
||||
|
||||
|
||||
class QueryOptions:
|
||||
@@ -210,7 +214,7 @@ class QueryOptions:
|
||||
cleaned_model = self.model_query(**cleaned_query)
|
||||
for i in cleaned_query:
|
||||
if hasattr(cleaned_model, i):
|
||||
last_dict[str(cleaned_query_by_model[i][0])] = str(cleaned_query_by_model[i][1])
|
||||
last_dict[str(cleaned_query_by_model[str(i)][0])] = str(cleaned_query_by_model[str(i)][1])
|
||||
self.data.query = last_dict
|
||||
|
||||
def convert(self) -> tuple:
|
||||
@@ -222,6 +226,4 @@ class QueryOptions:
|
||||
return ()
|
||||
if not self.data.query:
|
||||
return ()
|
||||
print('query', self.data)
|
||||
print('query', self.data.query)
|
||||
return tuple(self.table.convert(self.data.query))
|
||||
|
||||
Reference in New Issue
Block a user