""" Account 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 .function_handlers import AccountListEventMethods from .api_events import SuperUserAccountEvents AccountRecordsListEventMethods = MethodToEvent( name="AccountRecordsListEventMethods", events={ SuperUserAccountEvents.SuperUserListEvent.key: SuperUserAccountEvents.SuperUserListEvent, }, headers=[], errors=[], decorators_list=[TokenEventMiddleware.event_required], url="/list", method="POST", summary="List all accounts by given previligous", description="List all accounts by given previligous", ) def account_list_event_endpoint( request: Request, data: EndpointBaseRequestModel ) -> Dict[str, Any]: context_retriever = ContextRetrievers(func=account_list_event_endpoint) event_2_catch = AccountRecordsListEventMethods.retrieve_event( event_function_code=f"{SuperUserAccountEvents.SuperUserListEvent.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=event_2_catch.static_key, lang=context_retriever.token.lang ).as_dict( data=pagination_result.data, pagination=pagination_result.pagination.as_dict() ) AccountRecordsListEventMethods.endpoint_callable = account_list_event_endpoint AccountRecordsCreateEventMethods = MethodToEvent( name="AccountRecordsCreateEventMethods", events={ SuperUserAccountEvents.SuperUserCreateEvent.key: SuperUserAccountEvents.SuperUserCreateEvent, }, headers=[], errors=[], decorators_list=[TokenEventMiddleware.event_required], url="/create", method="POST", summary="Create Account via given data and previligous", description="Create Account via given data and previligous", ) def account_create_event_endpoint( request: Request, data: EndpointBaseRequestModel ) -> Dict[str, Any]: context_retriever = ContextRetrievers(func=account_create_event_endpoint) event_2_catch = AccountRecordsCreateEventMethods.retrieve_event( event_function_code=f"{SuperUserAccountEvents.SuperUserCreateEvent.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=event_2_catch.static_key, lang=context_retriever.token.lang ).as_dict( data=pagination_result.data, pagination=pagination_result.pagination.as_dict() ) AccountRecordsCreateEventMethods.endpoint_callable = account_create_event_endpoint AccountRecordsUpdateEventMethods = MethodToEvent( name="AccountRecordsUpdateEventMethods", events={ SuperUserAccountEvents.SuperUserUpdateEvent.key: SuperUserAccountEvents.SuperUserUpdateEvent, }, headers=[], errors=[], decorators_list=[TokenEventMiddleware.event_required], url="/update", method="POST", summary="Update Account via given data and previligous", description="Update Account via given data and previligous", ) def account_update_event_endpoint( request: Request, data: EndpointBaseRequestModel ) -> Dict[str, Any]: context_retriever = ContextRetrievers(func=account_update_event_endpoint) event_2_catch = AccountRecordsUpdateEventMethods.retrieve_event( event_function_code=f"{SuperUserAccountEvents.SuperUserUpdateEvent.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=event_2_catch.static_key, lang=context_retriever.token.lang ).as_dict( data=pagination_result.data, pagination=pagination_result.pagination.as_dict() ) AccountRecordsUpdateEventMethods.endpoint_callable = account_update_event_endpoint