updated Query options

This commit is contained in:
2025-01-30 14:24:42 +03:00
parent 822e4155a1
commit b664f64eb4
35 changed files with 852 additions and 589 deletions

View File

@@ -2,7 +2,6 @@
Validations package initialization.
"""
from .validation.cluster import ValidationsCluster

View File

@@ -5,7 +5,10 @@ Validation function handlers
from typing import Dict, Any
from fastapi import Request
from ApiLayers.AllConfigs.Redis.configs import RedisValidationKeysAction, RedisCategoryKeys
from ApiLayers.AllConfigs.Redis.configs import (
RedisValidationKeysAction,
RedisCategoryKeys,
)
from Services.Redis.Actions.actions import RedisActions
from Events.base_request_model import BaseRouteModel
@@ -22,7 +25,7 @@ class ValidateBase:
@property
def function_codes(self):
redis_function_codes= RedisActions.get_json(
redis_function_codes = RedisActions.get_json(
list_keys=[f"{self.redis_key}{self.url}"]
)
if redis_function_codes.status:
@@ -31,9 +34,13 @@ class ValidateBase:
@property
def intersection(self):
intersection = list(set(self.function_codes).intersection(set(self.reachable_codes)))
intersection = list(
set(self.function_codes).intersection(set(self.reachable_codes))
)
if not len(intersection) == 1:
raise ValueError("Users reachable function codes does not match or match more than one.")
raise ValueError(
"Users reachable function codes does not match or match more than one."
)
return intersection[0]
@@ -44,9 +51,11 @@ class RedisHeaderRetrieve(ValidateBase):
@property
def header(self):
"""
Headers: Headers which is merged with response model && language models of event
Headers: Headers which is merged with response model && language models of event
"""
redis_header= RedisActions.get_json(list_keys=[f"{self.redis_key}:{self.intersection}"])
redis_header = RedisActions.get_json(
list_keys=[f"{self.redis_key}:{self.intersection}"]
)
if redis_header.status:
return redis_header.first
raise ValueError("Header not found")
@@ -59,9 +68,11 @@ class RedisValidationRetrieve(ValidateBase):
@property
def validation(self):
"""
Validation: Validation of event which is merged with response model && language models of event
Validation: Validation of event which is merged with response model && language models of event
"""
redis_validation = RedisActions.get_json(list_keys=[f"{self.redis_key}:{self.intersection}"])
redis_validation = RedisActions.get_json(
list_keys=[f"{self.redis_key}:{self.intersection}"]
)
if redis_validation.status:
return redis_validation.first
raise ValueError("Header not found")
@@ -72,8 +83,8 @@ class ValidationsBoth(RedisHeaderRetrieve, RedisValidationRetrieve):
@property
def both(self) -> Dict[str, Any]:
"""
Headers: Headers which is merged with response model && language models of event
Validation: Validation of event which is merged with response model && language models of event
Headers: Headers which is merged with response model && language models of event
Validation: Validation of event which is merged with response model && language models of event
"""
return {"headers": self.header, "validation": self.validation}
@@ -85,14 +96,23 @@ class RetrieveValidation(BaseRouteModel):
"""
Retrieve validation by event function code
"""
if getattr(data, 'asked_field', "") not in ValidationsConfig.SUPPORTED_VALIDATIONS:
raise ValueError(f"Invalid asked field please retry with valid fields {ValidationsConfig.SUPPORTED_VALIDATIONS}")
if (
getattr(data, "asked_field", "")
not in ValidationsConfig.SUPPORTED_VALIDATIONS
):
raise ValueError(
f"Invalid asked field please retry with valid fields {ValidationsConfig.SUPPORTED_VALIDATIONS}"
)
reachable_codes = []
if cls.context_retriever.token.is_employee:
reachable_codes = cls.context_retriever.token.selected_company.reachable_event_codes
reachable_codes = (
cls.context_retriever.token.selected_company.reachable_event_codes
)
elif cls.context_retriever.token.is_occupant:
reachable_codes = cls.context_retriever.token.selected_occupant.reachable_event_codes
reachable_codes = (
cls.context_retriever.token.selected_occupant.reachable_event_codes
)
validate_dict = dict(url=data.url, reachable_code=reachable_codes)
if data.asked_field == "all":

View File

@@ -7,5 +7,5 @@ template_page_info = PageInfo(
description={"en": "template"},
icon="",
parent="",
url=""
url="",
)

View File

@@ -1,6 +1,7 @@
"""
Validation records request and response models.
"""
from typing import Optional
from pydantic import BaseModel

View File

@@ -27,11 +27,15 @@ ValidationEventMethods = MethodToEvent(
def authentication_login_with_domain_and_creds_endpoint(
request: Request, data: EndpointBaseRequestModel
request: Request, data: EndpointBaseRequestModel
) -> Dict[str, Any]:
function = ValidationEventMethods.retrieve_event(event_function_code=f"{validation_event.key}")
function = ValidationEventMethods.retrieve_event(
event_function_code=f"{validation_event.key}"
)
data = function.REQUEST_VALIDATOR(**data.data)
RetrieveValidation.context_retriever = ContextRetrievers(func=authentication_login_with_domain_and_creds_endpoint)
RetrieveValidation.context_retriever = ContextRetrievers(
func=authentication_login_with_domain_and_creds_endpoint
)
return function.endpoint_callable(request=request, data=data)