70 lines
2.6 KiB
Python
70 lines
2.6 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 Services, Service2Events
|
|
|
|
|
|
# List endpoint
|
|
ServiceEndpointListEvent = Event(
|
|
name="service_endpoint_list",
|
|
key="7da6ceac-925a-4faa-9cc5-3f34396b5684",
|
|
request_validator=None, # TODO: Add request validator
|
|
response_validator=None, # TODO: Add response validator
|
|
description="Super Users List services endpoint",
|
|
)
|
|
|
|
|
|
def service_endpoint_list_callable(data: PaginateOnly):
|
|
"""
|
|
List services endpoint callable method
|
|
"""
|
|
list_options = PaginateOnly(**data.model_dump())
|
|
with Services.new_session() as db_session:
|
|
if data.query:
|
|
services_list = Services.filter_all_system(
|
|
*Services.convert(data.query), db=db_session
|
|
)
|
|
else:
|
|
services_list = Services.filter_all_system(db=db_session)
|
|
pagination = Pagination(data=services_list)
|
|
pagination.change(**data.model_dump())
|
|
pagination_result = PaginationResult(data=services_list, pagination=pagination)
|
|
return EndpointResponse(
|
|
message="MSG0003-LIST", pagination_result=pagination_result
|
|
).response
|
|
|
|
|
|
ServiceEndpointListEvent.event_callable = service_endpoint_list_callable
|
|
|
|
# To events endpoint
|
|
ServiceEndpointToEventsEvent = Event(
|
|
name="service_endpoint_to_events",
|
|
key="7b6b0c6a-e3db-4353-a7df-ea49d2a67f8a",
|
|
request_validator=None, # TODO: Add request validator
|
|
response_validator=None, # TODO: Add response validator
|
|
description="Super Users List events of a service endpoint given service UUID",
|
|
)
|
|
|
|
|
|
def service_endpoint_to_events_callable(data: PaginateOnly):
|
|
"""
|
|
List events of a service given service UUID
|
|
"""
|
|
list_options = PaginateOnly(**data.model_dump())
|
|
with Service2Events.new_session() as db_session:
|
|
if data.query:
|
|
services_list = Service2Events.filter_all_system(
|
|
*Service2Events.convert(data.query), db=db_session
|
|
)
|
|
else:
|
|
services_list = Service2Events.filter_all_system(db=db_session)
|
|
pagination = Pagination(data=services_list)
|
|
pagination.change(**data.model_dump())
|
|
pagination_result = PaginationResult(data=services_list, pagination=pagination)
|
|
return EndpointResponse(
|
|
message="MSG0003-LIST", pagination_result=pagination_result
|
|
).response
|
|
|
|
|
|
ServiceEndpointToEventsEvent.event_callable = service_endpoint_to_events_callable
|