validations updated

This commit is contained in:
2025-01-19 21:06:00 +03:00
parent d6785ed36f
commit 8e34497c80
49 changed files with 2642 additions and 142 deletions

View File

@@ -1,5 +1,6 @@
"""Event Service API initialization"""
"""Validation Service API initialization"""
from .route_configs import get_route_configs
__all__ = ["get_route_configs"]

View File

@@ -0,0 +1,116 @@
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=False, # 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=False, # 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=False, # 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]

View File

@@ -0,0 +1,29 @@
"""
Validation records request and response models.
"""
from typing import TYPE_CHECKING, Dict, Any
from pydantic import BaseModel, Field, RootModel
from ApiEvents.base_request_model import BaseRequestModel
if TYPE_CHECKING:
from ApiValidations.Request import (
ListOptions,
)
class ValidationsPydantic(BaseModel):
class_model: str
reachable_event_code: str
lang: str
class InsertValidationRecordRequestModel(BaseRequestModel):
pass
class UpdateValidationRecordRequestModel(BaseRequestModel):
pass
class ListOptionsValidationRecordRequestModel(BaseRequestModel):
pass

View File

@@ -0,0 +1,97 @@
"""
Validation request models.
"""
from typing import TYPE_CHECKING, Dict, Any, Literal, Optional, TypedDict, Union
from pydantic import BaseModel, Field, model_validator, RootModel, ConfigDict
from ApiLibrary.common.line_number import get_line_number_for_error
from ApiValidations.Custom.validation_response import ValidationModel, ValidationParser
from ApiEvents.abstract_class import MethodToEvent
from ApiEvents.base_request_model import BaseRequestModel, DictRequestModel
from ApiValidations.Custom.token_objects import EmployeeTokenObject, OccupantTokenObject
from ApiValidations.Request.base_validations import ListOptions
from ErrorHandlers.Exceptions.api_exc import HTTPExceptionApi
from .models import ValidationsPydantic
if TYPE_CHECKING:
from fastapi import Request
class AllModelsImport:
@classmethod
def import_all_models(cls):
from ApiEvents.events.account.account_records import (
AccountListEventMethod,
AccountUpdateEventMethod,
AccountCreateEventMethod,
)
from ApiEvents.events.address.address import (
AddressListEventMethod,
AddressUpdateEventMethod,
AddressCreateEventMethod,
AddressSearchEventMethod,
)
return dict(
AccountListEventMethod=AccountListEventMethod,
AccountUpdateEventMethod=AccountUpdateEventMethod,
AccountCreateEventMethod=AccountCreateEventMethod,
AddressListEventMethod=AddressListEventMethod,
AddressUpdateEventMethod=AddressUpdateEventMethod,
AddressCreateEventMethod=AddressCreateEventMethod,
AddressSearchEventMethod=AddressSearchEventMethod,
)
class ValidationsBoth(MethodToEvent):
@classmethod
def retrieve_both_validations_and_headers(
cls, event: ValidationsPydantic
) -> Dict[str, Any]:
EVENT_MODELS = AllModelsImport.import_all_models()
return_single_model = EVENT_MODELS.get(event.class_model, None)
print("return_single_model", return_single_model, type(return_single_model))
# event_class_validation = getattr(return_single_model, "__event_validation__", None)
if not return_single_model:
raise HTTPExceptionApi(
error_code="",
lang="en",
loc=get_line_number_for_error(),
sys_msg="Validation code not found",
)
response_model = return_single_model.retrieve_event_response_model(event.reachable_event_code)
language_model_all = return_single_model.retrieve_language_parameters(function_code=event.reachable_event_code, language=event.lang)
language_model = language_model_all.get("language_model", None)
language_models = language_model_all.get("language_models", None)
validation = ValidationModel(response_model, language_model, language_models)
return {
"headers": validation.headers,
"validation": validation.validation,
"language_models": language_model_all,
}
class ValidationsValidations(MethodToEvent):
@classmethod
def retrieve_validations(
cls, event: ValidationsPydantic
) -> Dict[str, Any]:
return {}
class ValidationsHeaders(MethodToEvent):
@classmethod
def retrieve_headers(
cls, event: ValidationsPydantic
) -> Dict[str, Any]:
return {}

View File

@@ -0,0 +1,33 @@
from typing import Callable
class ValidationActions:
def __init__(self, function_code: str, func: Callable = None):
self.function_code = function_code
self.func = func
@classmethod
def retrieve_validation(cls):
"""
Retrieve validation [] by validation via [Response Model of Table]
"""
return
@classmethod
def retrieve_headers(cls):
"""
Retrieve headers for validations [] by event function code [Response Model of Table]
"""
return
@classmethod
def retrieve_validations_and_headers(cls):
"""
Retrieve validations and headers [] via event function code [Response Model of Table][]
"""
return
# Singleton class
validation_action = ValidationActions(function_code="")

View File

@@ -5,13 +5,13 @@ This module collects and registers all route configurations from different modul
to be used by the dynamic route creation system.
"""
from typing import Dict, List, Any
from typing import Dict, List, Any, TypeVar
from .events.validation.endpoints import VALIDATION_CONFIG
# Registry of all route configurations
ROUTE_CONFIGS = []
ROUTE_CONFIGS = [VALIDATION_CONFIG]
def get_route_configs() -> List[Dict[str, Any]]:
"""Get all registered route configurations."""
return []
return ROUTE_CONFIGS