updated list options and response validatore tested

This commit is contained in:
2025-01-30 17:19:23 +03:00
parent 9781cae858
commit 602ab2ffcc
6 changed files with 62 additions and 42 deletions

View File

@@ -35,7 +35,7 @@ def account_insert_event_endpoint(
event_2_catch = AccountRecordsEventMethods.retrieve_event(
event_function_code=f"{account_insert_super_user_event.key}"
)
context_retriever.event = event_2_catch
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
AccountListEventMethods.context_retriever = context_retriever
pagination_result = event_2_catch.endpoint_callable(data=data)

View File

@@ -1,9 +1,11 @@
from pydantic import BaseModel
from ApiLayers.ApiValidations.Request import ListOptions
from ApiLayers.Schemas import AccountRecords
from ApiLayers.LanguageModels.Request import (
LoginRequestLanguageModel,
SelectRequestLanguageModel,
)
# from ApiLayers.LanguageModels.Request import (
# LoginRequestLanguageModel,
# SelectRequestLanguageModel,
# )
from Events.Engine.abstract_class import Event
from .models import AccountRequestValidators
@@ -12,12 +14,22 @@ from .function_handlers import (
)
class SelectResponseAccount(BaseModel):
"""
Response model for account list.
"""
neighborhood_code: str
neighborhood_name: str
type_code: str
type_description: str
# Auth Login
account_insert_super_user_event = Event(
name="account_insert_super_user_event",
key="36a165fe-a2f3-437b-80ee-1ee44670fe70",
request_validator=ListOptions,
# response_validator=SelectRequestLanguageModel,
response_validator=SelectResponseAccount,
# language_models=[AccountRecords.__language_model__],
language_models=[],
statics="ACCOUNTS_LIST",

View File

@@ -44,26 +44,51 @@ class AccountListEventMethods(BaseRouteModel):
}
"""
@classmethod
def account_records_list(cls, data: Optional[Union[dict, ListOptions]]) -> PaginationResult:
from ApiLayers.Schemas import AddressNeighborhood
list_options_base = ListOptionsBase(
table=AccountRecords, list_options=data, model_query=None,
table=AddressNeighborhood, list_options=data, model_query=None,
)
db_session, query_options = list_options_base.init_list_options()
if cls.context_retriever.token.is_occupant:
AccountRecords.pre_query = AccountRecords.filter_all(
AccountRecords.company_id
== cls.context_retriever.token.selected_occupant.responsible_company_id,
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
AddressNeighborhood.neighborhood_code.icontains("10"),
db=db_session,
).query
elif cls.context_retriever.token.is_employee:
AccountRecords.pre_query = AccountRecords.filter_all(
AccountRecords.company_id ==
cls.context_retriever.token.selected_company.company_id,
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
AddressNeighborhood.neighborhood_code.icontains("9"),
db=db_session,
).query
records = AccountRecords.filter_all(*query_options.convert(), db=db_session)
return list_options_base.paginated_result(records=records)
records = AddressNeighborhood.filter_all(*query_options.convert(), db=db_session)
return list_options_base.paginated_result(
records=records, response_model=cls.context_retriever.RESPONSE_VALIDATOR
)
# @classmethod
# def account_records_list(cls, data: Optional[Union[dict, ListOptions]]) -> PaginationResult:
# list_options_base = ListOptionsBase(
# table=AccountRecords, list_options=data, model_query=None,
# )
# db_session, query_options = list_options_base.init_list_options()
# if cls.context_retriever.token.is_occupant:
# AccountRecords.pre_query = AccountRecords.filter_all(
# AccountRecords.company_id
# == cls.context_retriever.token.selected_occupant.responsible_company_id,
# db=db_session,
# ).query
# elif cls.context_retriever.token.is_employee:
# AccountRecords.pre_query = AccountRecords.filter_all(
# AccountRecords.company_id ==
# cls.context_retriever.token.selected_company.company_id,
# db=db_session,
# ).query
# records = AccountRecords.filter_all(*query_options.convert(), db=db_session)
# return list_options_base.paginated_result(
# records=records, response_model=cls.context_retriever.RESPONSE_VALIDATOR
# )
# @classmethod
# def account_records_list_flt_res(cls, list_options: ListOptions) -> PaginationResult: