wag-managment-api-service-v.../Events/AllEvents/events/account/account_records.py

52 lines
1.8 KiB
Python

"""
template related API endpoints.
"""
from typing import Any, Dict
from fastapi import Request
from Events.Engine.abstract_class import MethodToEvent
from Events.base_request_model import EndpointBaseRequestModel, ContextRetrievers
from ApiLayers.Middleware.token_event_middleware import TokenEventMiddleware
from ApiLayers.ApiValidations.Response.default_response import EndpointSuccessListResponse
from .api_events import account_insert_super_user_event
from .function_handlers import AccountListEventMethods
AccountRecordsEventMethods = MethodToEvent(
name="AccountRecordsEventMethods",
events={
account_insert_super_user_event.key: account_insert_super_user_event,
},
headers=[],
errors=[],
decorators_list=[TokenEventMiddleware.event_required],
url="/list",
method="POST",
summary="Login via domain and access key : [email] | [phone]",
description="Login to the system via domain, access key : [email] | [phone]",
)
def account_insert_event_endpoint(
request: Request, data: EndpointBaseRequestModel
) -> Dict[str, Any]:
context_retriever = ContextRetrievers(func=account_insert_event_endpoint)
event_2_catch = AccountRecordsEventMethods.retrieve_event(
event_function_code=f"{account_insert_super_user_event.key}"
)
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)
return EndpointSuccessListResponse(
code="ACCOUNTS_LIST", lang=context_retriever.token.lang
).as_dict(
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
)
AccountRecordsEventMethods.endpoint_callable = (
account_insert_event_endpoint
)