updated list options and response validatore tested

This commit is contained in:
berkay 2025-01-30 17:21:25 +03:00
parent 602ab2ffcc
commit af82f74eb6
4 changed files with 15 additions and 38 deletions

View File

@ -6,11 +6,9 @@
<component name="ChangeListManager">
<list default="true" id="b5202e0c-6ddf-4a56-a13a-e18798c4c7cf" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Events/AllEvents/events/account/account_records.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/events/account/account_records.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Events/AllEvents/events/account/api_events.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/events/account/api_events.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ApiLayers/Middleware/token_event_middleware.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/Middleware/token_event_middleware.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Events/AllEvents/events/account/function_handlers.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/events/account/function_handlers.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Events/base_request_model.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/base_request_model.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Services/PostgresDb/Models/pagination.py" beforeDir="false" afterPath="$PROJECT_DIR$/Services/PostgresDb/Models/pagination.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Events/AllEvents/template/template/function_handlers.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/template/template/function_handlers.py" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@ -102,7 +102,7 @@ class TokenEventMiddleware:
)
# Intersect function codes with user accers objects available event codes
reachable_event_codes = ["36a165fe-a2f3-437b-80ee-1ee44670fe70"]
# reachable_event_codes = ["36a165fe-a2f3-437b-80ee-1ee44670fe70"]
intersected_code = list(
set(function_code_list_of_event) & set(reachable_event_codes)
)

View File

@ -44,52 +44,29 @@ 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=AddressNeighborhood, list_options=data, model_query=None,
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:
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
AddressNeighborhood.neighborhood_code.icontains("10"),
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:
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
AddressNeighborhood.neighborhood_code.icontains("9"),
AccountRecords.pre_query = AccountRecords.filter_all(
AccountRecords.company_id ==
cls.context_retriever.token.selected_company.company_id,
db=db_session,
).query
records = AddressNeighborhood.filter_all(*query_options.convert(), db=db_session)
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
records=records, response_model=getattr(cls.context_retriever, 'RESPONSE_VALIDATOR', None)
)
# @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:
# list_options_base = ListOptionsBase(

View File

@ -65,4 +65,6 @@ class TemplateFunctions(BaseRouteModel):
db=db_session,
).query
records = AddressNeighborhood.filter_all(*query_options.convert(), db=db_session)
return list_options_base.paginated_result(records=records)
return list_options_base.paginated_result(
records=records, response_model=getattr(cls.context_retriever, 'RESPONSE_VALIDATOR', None)
)