97 lines
3.1 KiB
Python
97 lines
3.1 KiB
Python
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
|