from typing import Dict, Any from .models import ValidationsPydantic from ErrorHandlers.Exceptions.api_exc import HTTPExceptionApi from .validation import ( ValidationsBoth, ValidationsHeaders, ValidationsValidations, ) from ApiEvents.abstract_class import RouteFactoryConfig, EndpointFactoryConfig from ApiEvents.base_request_model import EndpointBaseRequestModel from ApiLibrary.common.line_number import get_line_number_for_error from Services.PostgresDb.Models.alchemy_response import DictJsonResponse from fastapi import Request, Path, Body from middleware.token_event_middleware import TokenEventMiddleware prefix = "/validation" @TokenEventMiddleware.validation_required async def validations_validations_select(request: Request, data: EndpointBaseRequestModel) -> Dict[str, Any]: """ Select validations. """ wrapped_context = getattr(validations_validations_select, "__wrapped__", None) auth_context = getattr(wrapped_context, "auth", None) validation_code = getattr(validations_validations_select, "validation_code", {"validation_code": None}) if not validation_code: raise HTTPExceptionApi( error_code="", lang="en", loc=get_line_number_for_error(), sys_msg="Validation code not found", ) validations_pydantic = ValidationsPydantic( class_model=validation_code.get("class", None), reachable_event_code=validation_code.get("reachable_event_code", None), lang=getattr(auth_context, "lang", None), ) validations_both = ValidationsBoth.retrieve_both_validations_and_headers(validations_pydantic) return {"status": "OK", "validation_code": validation_code, **validations_both } @TokenEventMiddleware.validation_required async def validations_headers_select(request: Request, data: EndpointBaseRequestModel) -> Dict[str, Any]: """ Select headers. """ ValidationsHeaders.retrieve_headers() return { "status": "OK", } @TokenEventMiddleware.validation_required async def validations_validations_and_headers_select(request: Request, data: EndpointBaseRequestModel) -> Dict[str, Any]: """ Select validations and headers. """ ValidationsBoth.retrieve_both_validations_and_headers() return { "status": "OK", } VALIDATION_CONFIG_MAIN =RouteFactoryConfig( name="validations", prefix=prefix, tags=["Validation"], include_in_schema=True, endpoints=[ EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/select", url_of_endpoint=f"{prefix}/validations/select", endpoint="/select", method="POST", summary="Select company or occupant type", description="Select company or occupant type", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=validations_validations_select, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/headers/select", url_of_endpoint=f"{prefix}/headers/select", endpoint="/headers/select", method="POST", summary="Select company or occupant type", description="Select company or occupant type", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=validations_headers_select, ), EndpointFactoryConfig( url_prefix=prefix, url_endpoint="/both/select", url_of_endpoint=f"{prefix}/validationsAndHeaders/select", endpoint="/both/select", method="POST", summary="Select company or occupant type", description="Select company or occupant type", is_auth_required=True, # Needs token_dict is_event_required=False, endpoint_function=validations_validations_and_headers_select, ), ], ) VALIDATION_CONFIG = VALIDATION_CONFIG_MAIN.as_dict() VALIDATION_ENDPOINTS = [endpoint.url_of_endpoint for endpoint in VALIDATION_CONFIG_MAIN.endpoints]