99 lines
2.9 KiB
Python
99 lines
2.9 KiB
Python
from ApiControllers.abstracts.event_clusters import Event
|
|
from Validations.building.building.validations import (
|
|
REQUESTEWFAZCDMPVZHIWOKZEJBIEUDAFBNXFEEAEGSELVGGCDMWLQPYMRAEEABSRQJUFBIMFEEADXK,
|
|
)
|
|
from Controllers.Postgres.pagination import Pagination, PaginationResult, PaginateOnly
|
|
from Controllers.Postgres.response import EndpointResponse
|
|
from Schemas import Build
|
|
|
|
|
|
# List endpoint
|
|
BuildingListEvent = Event(
|
|
name="building_list",
|
|
key="e675d36a-6772-44a8-b153-9a8d55e0f560",
|
|
request_validator=None, # TODO: Add request validator
|
|
response_validator=None, # TODO: Add response validator
|
|
description="List events of buildings endpoint",
|
|
)
|
|
|
|
# Create endpoint
|
|
BuildingCreateEvent = Event(
|
|
name="building_create",
|
|
key="d79e3bdc-8f75-41d0-8eeb-dd9893d7ea0d",
|
|
request_validator=None, # TODO: Add request validator
|
|
response_validator=None, # TODO: Add response validator
|
|
description="Create events of buildings endpoint",
|
|
)
|
|
|
|
# Update endpoint
|
|
BuildingUpdateEvent = Event(
|
|
name="building_update",
|
|
key="45e1bb8c-c521-4013-9e99-d3a58204bc5f",
|
|
request_validator=None, # TODO: Add request validator
|
|
response_validator=None, # TODO: Add response validator
|
|
description="Update events of buildings endpoint",
|
|
)
|
|
|
|
|
|
def building_list_callable(list_options: PaginateOnly):
|
|
"""
|
|
Example callable method
|
|
"""
|
|
list_options = PaginateOnly(**list_options.model_dump())
|
|
with Build.new_session() as db_session:
|
|
if list_options.query:
|
|
buildings_list = Build.filter_all(
|
|
*Build.convert(list_options.query), db=db_session
|
|
)
|
|
else:
|
|
buildings_list = Build.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,
|
|
request=REQUESTEWFAZCDMPVZHIWOKZEJBIEUDAFBNXFEEAEGSELVGGCDMWLQPYMRAEEABSRQJUFBIMFEEADXK,
|
|
).response
|
|
|
|
|
|
BuildingListEvent.event_callable = building_list_callable
|
|
|
|
|
|
def building_create_callable():
|
|
"""
|
|
Example callable method
|
|
"""
|
|
return {
|
|
"completed": True,
|
|
"message": "Example callable method 2",
|
|
"info": {
|
|
"host": "example_host",
|
|
"user_agent": "example_user_agent",
|
|
},
|
|
}
|
|
|
|
|
|
BuildingCreateEvent.event_callable = building_create_callable
|
|
|
|
|
|
def building_update_callable():
|
|
"""
|
|
Example callable method
|
|
"""
|
|
return {
|
|
"completed": True,
|
|
"message": "Example callable method 2",
|
|
"info": {
|
|
"host": "example_host",
|
|
"user_agent": "example_user_agent",
|
|
},
|
|
}
|
|
|
|
|
|
BuildingUpdateEvent.event_callable = building_update_callable
|