event file updated

This commit is contained in:
2025-01-30 23:55:54 +03:00
parent af82f74eb6
commit 1fe88e226a
121 changed files with 2726 additions and 180 deletions

View File

@@ -0,0 +1,21 @@
from Events.Engine.abstract_class import Event
from ApiLayers.LanguageModels.Request import (
LoginRequestLanguageModel,
)
from models import TemplateResponseModels, TemplateRequestModels
from function_handlers import TemplateFunctions
# Auth Login
template_event = Event(
name="authentication_login_super_user_event",
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
request_validator=TemplateRequestModels.TemplateRequestModelX,
language_models=[LoginRequestLanguageModel],
response_validation_static="LOGIN_SUCCESS",
description="Login super user",
)
template_event.endpoint_callable = TemplateFunctions.template_example_function()

View File

@@ -0,0 +1,14 @@
from Events.Engine.abstract_class import CategoryCluster
from info import template_page_info
TemplateCluster = CategoryCluster(
name="TemplateCluster",
tags=["template"],
prefix="/template",
description="Template cluster",
pageinfo=template_page_info,
endpoints={},
include_in_schema=True,
sub_category=[],
)

View File

@@ -1,112 +0,0 @@
"""
Account records endpoint configurations.
"""
from ApiEvents.abstract_class import (
RouteFactoryConfig,
EndpointFactoryConfig,
endpoint_wrapper,
)
from ApiEvents.base_request_model import EndpointBaseRequestModel
from Services.PostgresDb.Models.alchemy_response import DictJsonResponse
from fastapi import Request, Path, Body
@endpoint_wrapper("/address/list")
async def address_list(request: "Request", data: EndpointBaseRequestModel):
"""Handle address list endpoint."""
auth_dict = address_list.auth
code_dict = getattr(address_list, "func_code", {"function_code": None})
return {"auth_dict": auth_dict, "code_dict": code_dict, "data": data}
@endpoint_wrapper("/address/create")
async def address_create(request: "Request", data: EndpointBaseRequestModel):
"""Handle address creation endpoint."""
return {
"data": data,
"request": str(request.headers),
"request_url": str(request.url),
"request_base_url": str(request.base_url),
}
@endpoint_wrapper("/address/update/{address_uu_id}")
async def address_update(
request: Request,
address_uu_id: str = Path(..., description="UUID of the address to update"),
request_data: EndpointBaseRequestModel = Body(..., description="Request body"),
):
"""
Handle address update endpoint.
Args:
request: FastAPI request object
address_uu_id: UUID of the address to update
request_data: Request body containing updated address data
Returns:
DictJsonResponse: Response containing updated address info
"""
auth_dict = address_update.auth
return DictJsonResponse(
data={
"address_uu_id": address_uu_id,
"data": request_data.root,
"request": str(request.headers),
"request_url": str(request.url),
"request_base_url": str(request.base_url),
}
)
prefix = "/address"
# Address Router Configuration
ADDRESS_CONFIG = RouteFactoryConfig(
name="address",
prefix=prefix,
tags=["Address"],
include_in_schema=True,
endpoints=[
EndpointFactoryConfig(
url_prefix=prefix,
url_endpoint="/list",
url_of_endpoint=f"{prefix}/list",
endpoint="/list",
method="POST",
summary="List Active/Delete/Confirm Address",
description="List Active/Delete/Confirm Address",
is_auth_required=True,
is_event_required=True,
endpoint_function=address_list,
),
EndpointFactoryConfig(
url_prefix=prefix,
url_endpoint="/create",
url_of_endpoint=f"{prefix}/create",
endpoint="/create",
method="POST",
summary="Create Address with given auth levels",
description="Create Address with given auth levels",
is_auth_required=False,
is_event_required=False,
endpoint_function=address_create,
),
EndpointFactoryConfig(
url_prefix=prefix,
url_endpoint="/{address_uu_id}",
url_of_endpoint="{prefix}/" + "{address_uu_id}",
endpoint="/{address_uu_id}",
method="PUT",
summary="Update Address with given auth levels",
description="Update Address with given auth levels",
is_auth_required=True,
is_event_required=True,
endpoint_function=address_update,
),
],
).as_dict()

View File

@@ -0,0 +1,70 @@
from typing import Union, Optional
from ApiLayers.ApiValidations.Request import ListOptions
from Events.base_request_model import BaseRouteModel, ListOptionsBase
from Services.PostgresDb.Models.pagination 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)
)

View File

@@ -0,0 +1,11 @@
from Events.Engine.abstract_class import PageInfo
template_page_info = PageInfo(
name="template",
title={"en": "template"},
description={"en": "template"},
icon="",
parent="",
url="",
)