177 lines
4.0 KiB
Python
177 lines
4.0 KiB
Python
from typing import Any, ClassVar, Dict, List, Optional
|
|
from uuid import UUID
|
|
|
|
from .pageinfo import PageInfo
|
|
|
|
|
|
class Event:
|
|
|
|
KEY_: str # static string uuid.uuid4().__str__()
|
|
RESPONSE_VALIDATOR: ClassVar["PydanticModel"]
|
|
REQUEST_VALIDATOR: ClassVar["PydanticModel"]
|
|
DESCRIPTION: str
|
|
EXTRA_OPTIONS: Optional[Dict[str, Any]] = None
|
|
|
|
def __init__(
|
|
self, key: UUID, request_validator: "PydanticModel", response_validator: "PydanticModel",
|
|
description: str, extra_options: Optional[Dict[str, Any]] = None
|
|
) -> None:
|
|
self.KEY_ = key
|
|
self.REQUEST_VALIDATOR = request_validator
|
|
self.RESPONSE_VALIDATOR = response_validator
|
|
self.DESCRIPTION = description
|
|
self.EXTRA_OPTIONS = extra_options
|
|
|
|
@property
|
|
def name(self):
|
|
return f"This is an event of {self.__class__.__name__}. Description: {self.DESCRIPTION}"
|
|
|
|
@property
|
|
def key(self):
|
|
return str(self.KEY_)
|
|
|
|
@abstractmethod
|
|
def endpoint_callable(request: "Request", data: Any):
|
|
"""
|
|
return cls.retrieve_event(event_function_code).retrieve_callable(token_dict, data)
|
|
"""
|
|
pass
|
|
|
|
|
|
class MethodToEvent:
|
|
"""
|
|
for all endpoint callable
|
|
def endpoint_callable(request: Request, data: PydanticModel):
|
|
return cls.retrieve_event(event_function_code).retrieve_callable(token_dict, data)
|
|
"""
|
|
EVENTS: list[Event]
|
|
HEADER_LANGUAGE_MODELS: list[Dict] # [Table.__language_model__ | Dict[__language_model__]]
|
|
ERRORS_LANGUAGE_MODELS: Optional[list[Dict]] # [Dict[ErrorCode][lang]]
|
|
|
|
URL: str
|
|
METHOD: str
|
|
SUMMARY: str
|
|
DESCRIPTION: str
|
|
EXTRA_OPTIONS: Optional[Dict[str, Any]] = None
|
|
|
|
def __init__(
|
|
self,
|
|
events: list[Event],
|
|
headers: list[Dict],
|
|
url: str,
|
|
method: str,
|
|
summary: str,
|
|
description: str,
|
|
errors: Optional[list[Dict]] = None,
|
|
extra_options: Optional[Dict[str, Any]] = None,
|
|
):
|
|
self.EVENTS = events
|
|
self.URL = url
|
|
self.METHOD = method
|
|
self.SUMMARY = summary
|
|
self.DESCRIPTION = description
|
|
self.HEADER_LANGUAGE_MODELS = headers
|
|
self.ERRORS_LANGUAGE_MODELS = errors
|
|
self.EXTRA_OPTIONS = extra_options
|
|
|
|
def retrieve_all_event_keys():
|
|
"""
|
|
self.EVENTS.iter()
|
|
[FUNCTION_CODE]
|
|
"""
|
|
pass
|
|
|
|
def retrieve_event(event_function_code: str):
|
|
if list_found := [event for event in self.EVENTS if str(event.key) == event_function_code]:
|
|
return list_found[0]
|
|
raise ValueError(f"Event with function code {event_function_code} not found")
|
|
|
|
def retrieve_redis_value() -> Dict:
|
|
"""
|
|
Key(f"METHOD_FUNCTION_CODES:{ClusterToMethod}:MethodEvent:Endpoint") : Value([FUNCTION_CODE, ...])
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
class CategoryCluster:
|
|
|
|
TAGS: list
|
|
PREFIX: str
|
|
PAGEINFO: PageInfo
|
|
DESCRIPTION: str
|
|
ENDPOINTS: list = [MethodToEvent]
|
|
SUBCATEGORY: Optional[List["CategoryCluster"]] = []
|
|
INCLUDE_IN_SCHEMA: Optional[bool] = True
|
|
|
|
def __init__(
|
|
self,
|
|
tags: list,
|
|
prefix: str,
|
|
description: str,
|
|
pageinfo: PageInfo,
|
|
endpoints: list,
|
|
sub_category: list = [],
|
|
include_in_schema: Optional[bool] = True,
|
|
):
|
|
self.TAGS = tags
|
|
self.PREFIX = prefix
|
|
self.PAGEINFO = pageinfo
|
|
self.DESCRIPTION = description
|
|
self.ENDPOINTS = endpoints or []
|
|
self.SUBCATEGORY = sub_category or []
|
|
self.INCLUDE_IN_SCHEMA = include_in_schema
|
|
|
|
|
|
def retrieve_all_function_codes():
|
|
"""
|
|
[FUNCTION_CODE, ...]
|
|
self.ENDPOINTS -> iter()
|
|
"""
|
|
pass
|
|
|
|
def retrieve_page_info():
|
|
"""
|
|
PAGE_INFO:ClusterToMethod = {
|
|
"PageInfo": {...}
|
|
"subCategory": PAGE_INFO:ClusterToMethod
|
|
}
|
|
PAGE_INFO:ClusterToMethod = {
|
|
"PageInfo": {...}
|
|
"subCategory": PAGE_INFO:ClusterToMethod
|
|
}
|
|
"""
|
|
pass
|
|
|
|
def retrieve_redis_value() -> Dict:
|
|
"""
|
|
Key(CLUSTER_FUNCTION_CODES:ClusterToMethod) : Value(PAGE_INFO, [FUNCTION_CODE, ...])
|
|
"""
|
|
pass
|
|
|
|
|
|
class PageInfo:
|
|
|
|
NAME: str
|
|
BUTTON_NAME: str
|
|
PAGE_URL: str
|
|
PAGEINFO: "PageInfo"
|
|
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
title: Dict[str, Any],
|
|
description: Dict[str, Any],
|
|
icon: str,
|
|
parent: str,
|
|
url: str,
|
|
):
|
|
self.NAME = name
|
|
self.TITLE = title
|
|
self.DESCRIPTION = description
|
|
self.ICON = icon
|
|
self.PARENT = parent
|
|
|
|
|
|
|