3 services are updated

This commit is contained in:
2025-05-13 18:29:02 +03:00
parent cd62d96158
commit 6dfa17c5e6
54 changed files with 1374 additions and 148 deletions

View File

@@ -0,0 +1,3 @@
__all__ = []

View File

@@ -0,0 +1,147 @@
from typing import Any
from fastapi import APIRouter, Depends
from index import endpoints_index
from events.application.cluster import ApplicationRouterCluster
from api_validations.defaults.validations import CommonHeaders
from api_validations.response.pagination import PaginateOnly
from api_middlewares.token_provider import TokenProvider
application_endpoint_route = APIRouter(prefix="/application", tags=["Application Cluster"])
application_list_all = "ApplicationListAll"
@application_endpoint_route.post(
path="/list/all",
description="List all applications endpoint",
operation_id=endpoints_index[application_list_all],
)
def application_list_all_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_list_all)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_list_available = "ApplicationListAvailable"
@application_endpoint_route.post(
path="/list/available",
description="List available applications endpoint",
operation_id=endpoints_index[application_list_available],
)
def application_list_available_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_list_available)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_list_appended = "ApplicationListAppended"
@application_endpoint_route.post(
path="/list/appended",
description="List appended applications endpoint",
operation_id=endpoints_index[application_list_appended],
)
def application_list_appended_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_list_appended)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_register_service = "ApplicationRegisterService"
@application_endpoint_route.post(
path="/register/service",
description="Register service endpoint",
operation_id=endpoints_index[application_register_service],
)
def application_register_service_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_register_service)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_unregister_service = "ApplicationUnRegisterService"
@application_endpoint_route.post(
path="/unregister/service",
description="Unregister service endpoint",
operation_id=endpoints_index[application_unregister_service],
)
def application_unregister_service_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_unregister_service)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_create = "ApplicationCreate"
@application_endpoint_route.post(
path="/create",
description="Create application endpoint",
operation_id=endpoints_index[application_create],
)
def application_create_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_create)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_update = "ApplicationUpdate"
@application_endpoint_route.post(
path="/update/{application_uuid}",
description="Update application endpoint",
operation_id=endpoints_index[application_update],
)
def application_update_route(application_uuid: str, data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_update)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_bind_employee = "ApplicationBindEmployee"
@application_endpoint_route.post(
path="/bind/employee",
description="Bind employee endpoint",
operation_id=endpoints_index[application_bind_employee],
)
def application_bind_employee_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_bind_employee)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
application_bind_occupant = "ApplicationBindOccupant"
@application_endpoint_route.post(
path="/bind/occupant",
description="Bind occupant endpoint",
operation_id=endpoints_index[application_bind_occupant],
)
def application_bind_occupant_route(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = ApplicationRouterCluster.get_event_cluster(application_bind_occupant)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)

View File

@@ -0,0 +1,121 @@
from typing import Any
from fastapi import APIRouter, Depends
from index import endpoints_index
from events.events.cluster import EventsEndpointRouterCluster
from api_validations.defaults.validations import CommonHeaders
from api_validations.response.pagination import PaginateOnly
from api_middlewares.token_provider import TokenProvider
# Create API router
event_endpoint_route = APIRouter(prefix="/events", tags=["Event Actions"])
event_list_available = "EventsListAvailable"
@event_endpoint_route.post(
path="/list/available",
description="List available events endpoint",
operation_id=endpoints_index[event_list_available],
)
def event_list_available_route(
data: PaginateOnly,
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = EventsEndpointRouterCluster.get_event_cluster(event_list_available)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
event_list_appended = "EventsListAppended"
@event_endpoint_route.post(
path="/list/appended",
description="List appended events endpoint",
operation_id=endpoints_index[event_list_appended],
)
def event_list_appended_route(
data: PaginateOnly,
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = EventsEndpointRouterCluster.get_event_cluster(event_list_appended)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
event_register_service = "EventRegisterService"
@event_endpoint_route.post(
path="/register/service",
description="Register service endpoint",
operation_id=endpoints_index[event_register_service],
)
def event_register_service_route(
data: PaginateOnly,
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = EventsEndpointRouterCluster.get_event_cluster(event_register_service)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
event_unregister_service = "EventUnRegisterService"
@event_endpoint_route.post(
path="/unregister/service",
description="Unregister service endpoint",
operation_id=endpoints_index[event_unregister_service],
)
def event_unregister_service_route(
data: PaginateOnly,
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = EventsEndpointRouterCluster.get_event_cluster(event_unregister_service)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
event_bind_employee_extra = "EventBindExtraEmployee"
@event_endpoint_route.post(
path="/bind/employee/extra",
description="Bind employee extra endpoint",
operation_id=endpoints_index[event_bind_employee_extra],
)
def event_bind_employee_extra_route(
data: PaginateOnly,
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = EventsEndpointRouterCluster.get_event_cluster(event_bind_employee_extra)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)
event_bind_occupant_extra = "EventBindExtraOccupant"
@event_endpoint_route.post(
path="/bind/occupant/extra",
description="Bind occupant extra endpoint",
operation_id=endpoints_index[event_bind_occupant_extra],
)
def event_bind_occupant_extra_route(
data: PaginateOnly,
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
):
token_object = TokenProvider.get_dict_from_redis(token=headers.token)
event_founder_dict = dict(endpoint_code=headers.operation_id, token=token_object)
event_key = TokenProvider.retrieve_event_codes(**event_founder_dict)
FoundCluster = EventsEndpointRouterCluster.get_event_cluster(event_bind_occupant_extra)
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
return event_cluster_matched.event_callable(list_options=data)

View File

@@ -0,0 +1,17 @@
from fastapi import APIRouter
from .events.router import event_endpoint_route
from .services.router import services_endpoint_route
from .application.router import application_endpoint_route
def get_routes() -> list[APIRouter]:
return [event_endpoint_route, application_endpoint_route, services_endpoint_route]
def get_safe_endpoint_urls() -> list[tuple[str, str]]:
return [
("/", "GET"),
("/docs", "GET"),
("/redoc", "GET"),
("/openapi.json", "GET"),
("/metrics", "GET"),
]

View File

@@ -0,0 +1,13 @@
from typing import Any
from fastapi import APIRouter, Depends
from index import endpoints_index
# from events.services.cluster import ServicesEndpointRouterCluster
from api_validations.defaults.validations import CommonHeaders
from api_validations.response.pagination import PaginateOnly
from api_middlewares.token_provider import TokenProvider
# Create API router
services_endpoint_route = APIRouter(prefix="/services", tags=["Service Cluster"])

View File

@@ -0,0 +1,69 @@
from typing import Any
from fastapi import APIRouter, Depends
from sqlalchemy import func
from schemas import AccountRecords
from endpoints.index import endpoints_index
from events.event_endpoints.cluster import EventsEndpointRouterCluster
from api_validations.defaults.validations import CommonHeaders
from api_validations.response.pagination import PaginateOnly
from api_middlewares.token_provider import TokenProvider
test_endpoint_route = APIRouter(prefix="/tests", tags=["Endpoint Tests"])
account_records_all = "AccountRecordsAll"
@test_endpoint_route.get(
path="/account/records/all",
description="Account records endpoint",
operation_id=endpoints_index[account_records_all],
)
def account_records_all_route(headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
with AccountRecords.new_session() as db_session:
AccountRecords.set_session(db_session)
account_records_positive_list = db_session.query(func.sum(AccountRecords.currency_value)
).filter(AccountRecords.currency_value > 0
).order_by(AccountRecords.bank_date.desc()).first()
account_records_negative_list = db_session.query(func.sum(AccountRecords.currency_value)
).filter(AccountRecords.currency_value < 0
).order_by(AccountRecords.bank_date.desc()).first()
return {
"message": "MSG0003-LIST",
"data": {
"debt": float(account_records_negative_list),
"budget": float(account_records_positive_list),
"total": float(account_records_positive_list) + float(account_records_negative_list),
"lastPayment": account_records_data.bank_date,
},
"completed": True,
}
account_records_monthly = "AccountRecordsMonthly"
@test_endpoint_route.get(
path="/account/records/monthly",
description="Account records endpoint",
operation_id=endpoints_index[account_records_monthly],
)
def account_records_monthly_route(headers: CommonHeaders = Depends(CommonHeaders.as_dependency)):
with AccountRecords.new_session() as db_session:
account_records_positive_list = db_session.query(func.sum(AccountRecords.currency_value)).filter(
AccountRecords.bank_date_y == datetime.date.today().year,
AccountRecords.bank_date_m == datetime.date.today().month,
).order_by(AccountRecords.bank_date.desc()).first()
account_records_negative_list = db_session.query(func.sum(AccountRecords.currency_value)).filter(
AccountRecords.bank_date_y == datetime.date.today().year,
AccountRecords.bank_date_m == datetime.date.today().month,
).order_by(AccountRecords.bank_date.desc()).first()
return {
"message": "MSG0003-LIST",
"data": {
"debt": float(account_records_negative_list),
"budget": float(account_records_positive_list),
"total": float(account_records_positive_list) + float(account_records_negative_list),
"lastPayment": account_records_data.bank_date,
},
"completed": True,
}