event decarotor checked & event 2 endpoint dynmc create is tested

This commit is contained in:
2025-01-15 23:40:55 +03:00
parent 76d286b519
commit 049a7c1e11
12 changed files with 369 additions and 173 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -20,12 +20,20 @@ RUN poetry config virtualenvs.create false \
# Copy application code
COPY DockerApiServices/AllApiNeeds /app/
COPY ErrorHandlers /app/ErrorHandlers
COPY LanguageModels /app/LanguageModels
COPY ApiLibrary /app/ApiLibrary
COPY ApiValidations /app/ApiValidations
COPY AllConfigs /app/AllConfigs
COPY ErrorHandlers /app/ErrorHandlers
COPY Schemas /app/Schemas
COPY Services /app/Services
COPY ApiServices /app/ApiServices
# Copy Events structure with consistent naming
COPY ApiEvents/EventServiceApi /app/events
COPY ApiEvents/utils.py /app/events/utils.py
COPY ApiEvents/abstract_class.py /app/events/abstract_class.py
# Set Python path to include app directory
ENV PYTHONPATH=/app \