events started
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
template related API endpoints.
|
||||
Account related API endpoints.
|
||||
"""
|
||||
from typing import Any, Dict
|
||||
from fastapi import Request
|
||||
@@ -9,43 +9,120 @@ from Events.base_request_model import EndpointBaseRequestModel, ContextRetriever
|
||||
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
|
||||
from .api_events import SuperUserAccountEvents
|
||||
|
||||
|
||||
AccountRecordsEventMethods = MethodToEvent(
|
||||
name="AccountRecordsEventMethods",
|
||||
AccountRecordsListEventMethods = MethodToEvent(
|
||||
name="AccountRecordsListEventMethods",
|
||||
events={
|
||||
account_insert_super_user_event.key: account_insert_super_user_event,
|
||||
SuperUserAccountEvents.SuperUserListEvent.key: SuperUserAccountEvents.SuperUserListEvent,
|
||||
},
|
||||
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]",
|
||||
summary="List all accounts by given previligous",
|
||||
description="List all accounts by given previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_insert_event_endpoint(
|
||||
def account_list_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 = 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="ACCOUNTS_LIST", lang=context_retriever.token.lang
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AccountRecordsEventMethods.endpoint_callable = (
|
||||
account_insert_event_endpoint
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user