created design pattern
This commit is contained in:
27
ApiServices/BuildingService/Events/spaces/cluster.py
Normal file
27
ApiServices/BuildingService/Events/spaces/cluster.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from ApiControllers.abstracts.event_clusters import EventCluster, RouterCluster
|
||||
from .supers_events import (
|
||||
BuildLivingSpaceListEvent,
|
||||
BuildLivingSpaceCreateEvent,
|
||||
BuildLivingSpaceUpdateEvent,
|
||||
)
|
||||
|
||||
BuildLivingSpaceRouterCluster = RouterCluster(name="BuildLivingSpaceRouterCluster")
|
||||
|
||||
BuildLivingSpaceEventClusterList = EventCluster(
|
||||
name="BuildLivingSpaceList", endpoint_uu_id="ad17c019-3050-4c41-ab6f-9ce43290e81a"
|
||||
)
|
||||
BuildLivingSpaceEventClusterList.add_event(BuildLivingSpaceListEvent)
|
||||
|
||||
BuildLivingSpaceEventClusterCreate = EventCluster(
|
||||
name="BuildCreate", endpoint_uu_id="ed9a0303-14e2-46fe-bec0-d395c29801ff"
|
||||
)
|
||||
BuildLivingSpaceEventClusterCreate.add_event(BuildLivingSpaceCreateEvent)
|
||||
|
||||
BuildLivingSpaceEventClusterUpdate = EventCluster(
|
||||
name="BuildUpdate", endpoint_uu_id="c62bb3dc-03c0-406c-8bbc-0e1f75a6420c"
|
||||
)
|
||||
BuildLivingSpaceEventClusterUpdate.add_event(BuildLivingSpaceUpdateEvent)
|
||||
|
||||
BuildLivingSpaceRouterCluster.set_event_cluster(BuildLivingSpaceEventClusterList)
|
||||
BuildLivingSpaceRouterCluster.set_event_cluster(BuildLivingSpaceEventClusterCreate)
|
||||
BuildLivingSpaceRouterCluster.set_event_cluster(BuildLivingSpaceEventClusterUpdate)
|
||||
96
ApiServices/BuildingService/Events/spaces/supers_events.py
Normal file
96
ApiServices/BuildingService/Events/spaces/supers_events.py
Normal file
@@ -0,0 +1,96 @@
|
||||
from ApiControllers.abstracts.event_clusters import Event
|
||||
from Controllers.Postgres.pagination import Pagination, PaginationResult, PaginateOnly
|
||||
from Controllers.Postgres.response import EndpointResponse
|
||||
from Schemas import BuildLivingSpace
|
||||
|
||||
|
||||
# List endpoint
|
||||
BuildLivingSpaceListEvent = Event(
|
||||
name="build_living_space_list",
|
||||
key="d16c692f-5597-493a-90fe-b2bfe0d1c163",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="List events of build living spaces endpoint",
|
||||
)
|
||||
|
||||
# Create endpoint
|
||||
BuildLivingSpaceCreateEvent = Event(
|
||||
name="build_living_space_create",
|
||||
key="8ed0929e-9c96-4e81-b073-e3578ca13f37",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Create events of build living spaces endpoint",
|
||||
)
|
||||
|
||||
# Update endpoint
|
||||
BuildLivingSpaceUpdateEvent = Event(
|
||||
name="build_living_space_update",
|
||||
key="ece55fa6-afba-4c34-bd2e-f39a4cdd6b5c",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Update events of build living spaces endpoint",
|
||||
)
|
||||
|
||||
|
||||
def build_living_space_list_callable(list_options: PaginateOnly):
|
||||
"""
|
||||
List callable method
|
||||
"""
|
||||
list_options = PaginateOnly(**list_options.model_dump())
|
||||
with BuildLivingSpace.new_session() as db_session:
|
||||
if list_options.query:
|
||||
buildings_list = BuildLivingSpace.filter_all(
|
||||
*BuildLivingSpace.convert(list_options.query), db=db_session
|
||||
)
|
||||
else:
|
||||
buildings_list = BuildLivingSpace.filter_all(db=db_session)
|
||||
pagination = Pagination(data=buildings_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(
|
||||
data=buildings_list,
|
||||
pagination=pagination,
|
||||
# response_model="",
|
||||
).pagination.as_dict
|
||||
return EndpointResponse(
|
||||
message="MSG0003-LIST",
|
||||
pagination_result=pagination_result,
|
||||
).response
|
||||
|
||||
|
||||
BuildLivingSpaceListEvent.event_callable = build_living_space_list_callable
|
||||
|
||||
|
||||
def build_living_space_create_callable(data: dict):
|
||||
"""
|
||||
Create callable method
|
||||
"""
|
||||
with BuildLivingSpace.new_session() as db_session:
|
||||
return {
|
||||
"completed": True,
|
||||
"message": "Build living space created",
|
||||
"info": {
|
||||
"host": "example_host",
|
||||
"user_agent": "example_user_agent",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
BuildLivingSpaceCreateEvent.event_callable = build_living_space_create_callable
|
||||
|
||||
|
||||
def build_living_space_update_callable(data: dict):
|
||||
"""
|
||||
Update callable method
|
||||
"""
|
||||
with BuildLivingSpace.new_session() as db_session:
|
||||
return {
|
||||
"completed": True,
|
||||
"message": "Build living space updated",
|
||||
"info": {
|
||||
"host": "example_host",
|
||||
"user_agent": "example_user_agent",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
BuildLivingSpaceUpdateEvent.event_callable = build_living_space_update_callable
|
||||
Reference in New Issue
Block a user