event decarotor checked & event 2 endpoint dynmc create is tested
This commit is contained in:
@@ -15,7 +15,7 @@ from fastapi.routing import APIRoute
|
||||
from middleware.auth_middleware import MiddlewareModule
|
||||
from pydantic import BaseModel
|
||||
from AllConfigs.main import MainConfig as Config
|
||||
from ApiEvents.EventServiceApi.route_configs import get_route_configs
|
||||
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -99,21 +99,35 @@ def get_all_routers() -> tuple[List[APIRouter], Dict[str, List[str]]]:
|
||||
Returns:
|
||||
tuple: (routers, protected_routes)
|
||||
"""
|
||||
from events.route_configs import get_route_configs
|
||||
|
||||
routers = []
|
||||
all_protected_routes = {}
|
||||
|
||||
# Get route configurations from the registry
|
||||
route_configs = get_route_configs()
|
||||
|
||||
factory_all = []
|
||||
for config in route_configs:
|
||||
factory = EnhancedEndpointFactory(config)
|
||||
|
||||
# Create endpoints from configuration
|
||||
for endpoint_config in config['endpoints']:
|
||||
for endpoint_dict in config['endpoints']:
|
||||
endpoint_config = EndpointFactoryConfig(
|
||||
endpoint=endpoint_dict['endpoint'],
|
||||
method=endpoint_dict['method'],
|
||||
summary=endpoint_dict['summary'],
|
||||
description=endpoint_dict['description'],
|
||||
endpoint_function=endpoint_dict['endpoint_function'],
|
||||
is_auth_required=endpoint_dict['is_auth_required'],
|
||||
is_event_required=endpoint_dict['is_event_required'],
|
||||
extra_options=endpoint_dict.get('extra_options', {})
|
||||
)
|
||||
factory.create_endpoint(endpoint_config)
|
||||
factory_all.append(
|
||||
endpoint_config.__dict__
|
||||
)
|
||||
|
||||
# Add router and protected routes
|
||||
routers.append(factory.get_router())
|
||||
all_protected_routes.update(factory.get_protected_routes())
|
||||
|
||||
return routers, all_protected_routes
|
||||
@@ -95,25 +95,15 @@ class MiddlewareModule:
|
||||
"""
|
||||
|
||||
@wraps(func)
|
||||
async def wrapper(request: Request, *args, **kwargs):
|
||||
try:
|
||||
# Get token from header
|
||||
_, token = cls.get_access_token(request)
|
||||
|
||||
# Validate token and get user data
|
||||
token_data = await cls.validate_token(token)
|
||||
|
||||
# Add user data to request state for use in endpoint
|
||||
request.state.user = token_data
|
||||
|
||||
# Call the original endpoint function
|
||||
return await func(request, *args, **kwargs)
|
||||
|
||||
except HTTPExceptionApi:
|
||||
raise HTTPExceptionApi(error_code="NOT_AUTHORIZED", lang="tr")
|
||||
except Exception as e:
|
||||
raise HTTPExceptionApi(error_code="NOT_AUTHORIZED", lang="tr")
|
||||
|
||||
def wrapper(request: Request, *args, **kwargs):
|
||||
from ApiServices import TokenService
|
||||
# Get token from header
|
||||
# token = TokenService.get_access_token_from_request(request=request)
|
||||
# print(token)
|
||||
# if not token:
|
||||
# raise HTTPExceptionApi(error_code="NOT_AUTHORIZED", lang="tr")
|
||||
# Call the original endpoint function
|
||||
return func(request, *args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user