new api service and logic implemented
This commit is contained in:
21
Events/Engine/__init__.py
Normal file
21
Events/Engine/__init__.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""ApiEvents package initialization.
|
||||
|
||||
This module serves as the main entry point for the ApiEvents package,
|
||||
making common utilities and base classes available for all API services.
|
||||
"""
|
||||
|
||||
from .abstract_class import (
|
||||
MethodToEvent,
|
||||
PageInfo,
|
||||
ClusterToMethod,
|
||||
Event,
|
||||
)
|
||||
# from .base_request_model import BaseRequestModel, DictRequestModel
|
||||
|
||||
# Re-export commonly used classes
|
||||
__all__ = [
|
||||
"MethodToEvent",
|
||||
"PageInfo",
|
||||
"ClusterToMethod",
|
||||
"Event",
|
||||
]
|
||||
176
Events/Engine/abstract_class.py
Normal file
176
Events/Engine/abstract_class.py
Normal file
@@ -0,0 +1,176 @@
|
||||
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
|
||||
|
||||
|
||||
|
||||
2
Events/Engine/set_defaults/run.py
Normal file
2
Events/Engine/set_defaults/run.py
Normal file
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
7
Events/Engine/set_defaults/setClusters.py
Normal file
7
Events/Engine/set_defaults/setClusters.py
Normal file
@@ -0,0 +1,7 @@
|
||||
import AllEvents.auth as auths_events
|
||||
import AllEvents.events as events_events
|
||||
import AllEvents.validations as validations_events
|
||||
|
||||
|
||||
for event in [*auths_events.__all__, *events_events.__all__, *validations_events.__all__]:
|
||||
print(event)
|
||||
Reference in New Issue
Block a user