event decarotor checked & event 2 endpoint dynmc create is tested
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import typing
|
||||
from collections.abc import Callable
|
||||
|
||||
from fastapi import Request
|
||||
from typing import Dict, Any
|
||||
|
||||
from ApiValidations.Custom.token_objects import (
|
||||
OccupantTokenObject,
|
||||
EmployeeTokenObject,
|
||||
@@ -17,12 +22,14 @@ from ApiValidations.Request import (
|
||||
ListOptions,
|
||||
)
|
||||
from Services.PostgresDb.Models.alchemy_response import AlchemyJsonResponse
|
||||
from ApiEvents.abstract_class import (
|
||||
from ApiValidations.Response import AccountRecordResponse
|
||||
from events.abstract_class import (
|
||||
MethodToEvent,
|
||||
RouteFactoryConfig,
|
||||
EndpointFactoryConfig,
|
||||
)
|
||||
from ApiValidations.Response import AccountRecordResponse
|
||||
|
||||
# from events.utils import with_token_event
|
||||
|
||||
|
||||
class AccountRecordsListEventMethods(MethodToEvent):
|
||||
@@ -355,3 +362,108 @@ class AccountRecordsPatchEventMethods(MethodToEvent):
|
||||
message="Account record patched successfully",
|
||||
result=account_record,
|
||||
)
|
||||
|
||||
|
||||
|
||||
def address_list(request: Request, data: dict) -> Dict[str, Any]:
|
||||
"""Handle address list endpoint."""
|
||||
# Access context through the handler
|
||||
handler = address_list.handler
|
||||
handler_context = address_list.handler.context
|
||||
function_name = AccountRecordsListEventMethods.__event_keys__.get(handler.function_code)
|
||||
original_function = getattr(AccountRecordsListEventMethods, function_name)
|
||||
# original_function(data, request)
|
||||
return {
|
||||
"data": data,
|
||||
"function_code": handler.function_code, # This will be the URL
|
||||
"token_dict": handler_context.get('token_dict'),
|
||||
"url_of_endpoint": handler_context.get('url_of_endpoint'),
|
||||
"request": str(request.headers),
|
||||
}
|
||||
|
||||
def address_create(request: Request, data: dict):
|
||||
"""Handle address creation endpoint."""
|
||||
return {
|
||||
"data": data,
|
||||
"request": str(request.headers),
|
||||
"request_url": str(request.url),
|
||||
"request_base_url": str(request.base_url),
|
||||
}
|
||||
|
||||
def address_search(request: Request, data: dict):
|
||||
"""Handle address search endpoint."""
|
||||
# Get function_code from the wrapper's closure
|
||||
function_code = address_search.function_code
|
||||
return {
|
||||
"data": data,
|
||||
"function_code": function_code
|
||||
}
|
||||
|
||||
def address_update(request: Request, address_uu_id: str, data: dict):
|
||||
"""Handle address update endpoint."""
|
||||
# Get function_code from the wrapper's closure
|
||||
function_code = address_update.function_code
|
||||
return {
|
||||
"address_uu_id": address_uu_id,
|
||||
"data": data,
|
||||
"function_code": function_code
|
||||
}
|
||||
|
||||
|
||||
# Account Records Router Configuration
|
||||
ACCOUNT_RECORDS_CONFIG = RouteFactoryConfig(
|
||||
name='account_records',
|
||||
prefix='/account/records',
|
||||
tags=['Account Records'],
|
||||
include_in_schema=True,
|
||||
endpoints=[
|
||||
EndpointFactoryConfig(
|
||||
url_prefix = "/account/records",
|
||||
url_endpoint="/address/list",
|
||||
url_of_endpoint = "/account/records/address/list",
|
||||
endpoint="/address/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 = "/account/records",
|
||||
url_endpoint="/address/create",
|
||||
url_of_endpoint = "/account/records/address/create",
|
||||
endpoint="/address/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 = "/account/records",
|
||||
url_endpoint="/address/search",
|
||||
url_of_endpoint = "/account/records/address/search",
|
||||
endpoint="/address/search",
|
||||
method="POST",
|
||||
summary="Search Address with given auth levels",
|
||||
description="Search Address with given auth levels",
|
||||
is_auth_required=True,
|
||||
is_event_required=True,
|
||||
endpoint_function=address_search
|
||||
),
|
||||
EndpointFactoryConfig(
|
||||
url_prefix = "/account/records",
|
||||
url_endpoint="/address/update/{address_uu_id}",
|
||||
url_of_endpoint="/account/records/address/update/{address_uu_id}",
|
||||
endpoint="/address/update/{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()
|
||||
|
||||
Reference in New Issue
Block a user