79 lines
2.5 KiB
Python
79 lines
2.5 KiB
Python
from typing import Union, Optional
|
|
|
|
from ApiLayers.ApiValidations.Request import ListOptions
|
|
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
|
from Services.PostgresService.controllers.pagination_controllers import PaginationResult
|
|
|
|
|
|
class Handlers:
|
|
"""Class for handling authentication functions"""
|
|
|
|
@classmethod # Requires no auth context
|
|
def handle_function(cls, **kwargs):
|
|
"""Handle function with kwargs"""
|
|
return
|
|
|
|
|
|
class TemplateFunctions(BaseRouteModel):
|
|
"""
|
|
Class for handling authentication functions
|
|
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
|
results as :
|
|
STATIC_MESSAGE & LANG retrieved from redis
|
|
{
|
|
"completed": true,
|
|
"message": STATIC_MESSAGE,
|
|
"lang": LANG,
|
|
"pagination": {
|
|
"size": 10,
|
|
"page": 2,
|
|
"allCount": 28366,
|
|
"totalCount": 18,
|
|
"totalPages": 2,
|
|
"pageCount": 8,
|
|
"orderField": ["type_code", "neighborhood_name"],
|
|
"orderType": ["asc", "desc"]
|
|
},
|
|
"data": [
|
|
{
|
|
"created_at": "2025-01-12 09:39:48 +00:00",
|
|
"active": true,
|
|
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
|
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
|
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
|
},
|
|
...
|
|
]
|
|
}
|
|
"""
|
|
|
|
@classmethod
|
|
def template_example_function_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,
|
|
)
|
|
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"),
|
|
db=db_session,
|
|
).query
|
|
elif cls.context_retriever.token.is_employee:
|
|
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
|
AddressNeighborhood.neighborhood_code.icontains("9"),
|
|
db=db_session,
|
|
).query
|
|
records = AddressNeighborhood.filter_all(
|
|
*query_options.convert(), db=db_session
|
|
)
|
|
return list_options_base.paginated_result(
|
|
records=records,
|
|
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
|
)
|