more services added
This commit is contained in:
@@ -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
|
||||
duty_types_route = APIRouter(prefix="/duty/types", tags=["Duty Types Cluster"])
|
||||
@@ -2,7 +2,7 @@ from typing import Any
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from index import endpoints_index
|
||||
# from events.services.cluster import ServicesEndpointRouterCluster
|
||||
from events.services.cluster import ServicesRouterCluster
|
||||
|
||||
from api_validations.defaults.validations import CommonHeaders
|
||||
from api_validations.response.pagination import PaginateOnly
|
||||
@@ -10,4 +10,65 @@ from api_middlewares.token_provider import TokenProvider
|
||||
|
||||
|
||||
# Create API router
|
||||
services_endpoint_route = APIRouter(prefix="/services", tags=["Service Cluster"])
|
||||
services_route = APIRouter(prefix="/services", tags=["Service Cluster"])
|
||||
|
||||
|
||||
services_list = "ServicesList"
|
||||
@services_route.post(
|
||||
path="/list",
|
||||
description="List all services endpoint",
|
||||
operation_id=endpoints_index[services_list],
|
||||
)
|
||||
def services_list(data: PaginateOnly, headers: CommonHeaders = Depends(CommonHeaders)):
|
||||
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 = ServicesRouterCluster.get_event_cluster(services_list)
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(list_options=data)
|
||||
|
||||
|
||||
services_create = "ServicesCreate"
|
||||
@services_route.post(
|
||||
path="/create",
|
||||
description="Create service endpoint",
|
||||
operation_id=endpoints_index[services_create],
|
||||
)
|
||||
def services_create(data, headers: CommonHeaders = Depends(CommonHeaders)):
|
||||
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 = ServicesRouterCluster.get_event_cluster(services_create)
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(list_options=data)
|
||||
|
||||
|
||||
services_update = "ServicesUpdate"
|
||||
@services_route.post(
|
||||
path="/update/{uu_id}",
|
||||
description="Update service endpoint",
|
||||
operation_id=endpoints_index[services_update],
|
||||
)
|
||||
def services_update(uu_id: str, data, headers: CommonHeaders = Depends(CommonHeaders)):
|
||||
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 = ServicesRouterCluster.get_event_cluster(services_update)
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(list_options=data)
|
||||
|
||||
|
||||
services_delete = "ServicesDelete"
|
||||
@services_route.post(
|
||||
path="/delete/{uu_id}",
|
||||
description="Delete service endpoint",
|
||||
operation_id=endpoints_index[services_delete],
|
||||
)
|
||||
def services_delete(uu_id: str, headers: CommonHeaders = Depends(CommonHeaders)):
|
||||
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 = ServicesRouterCluster.get_event_cluster(services_delete)
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(list_options=data)
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from .events.cluster import EventsEndpointRouterCluster
|
||||
from .application.cluster import ApplicationRouterCluster
|
||||
# from .services.cluster import ServicesEndpointRouterCluster
|
||||
|
||||
|
||||
__all__ = []
|
||||
__all__ = ["EventsEndpointRouterCluster", "ApplicationRouterCluster"]
|
||||
@@ -103,10 +103,11 @@ ApplicationBindOccupantEvent = Event(
|
||||
def application_list_all_callable(list_options: PaginateOnly):
|
||||
list_options = PaginateOnly(**list_options.model_dump())
|
||||
with Applications.new_session() as db_session:
|
||||
Applications.set_session(db_session)
|
||||
if list_options.query:
|
||||
applications_list = Applications.filter_all(*Applications.convert(list_options.query), db=db_session)
|
||||
applications_list = Applications.query.filter(*Applications.convert(list_options.query))
|
||||
else:
|
||||
applications_list = Applications.filter_all(db=db_session)
|
||||
applications_list = Applications.query.filter()
|
||||
pagination = Pagination(data=applications_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(data=applications_list, pagination=pagination)
|
||||
@@ -131,19 +132,13 @@ def application_list_available_callable(list_options: PaginateOnly):
|
||||
list_options.query.pop("service_uu_id__ilike", None)
|
||||
list_options.query.pop("service_uu_id", None)
|
||||
with Applications.new_session() as db_session:
|
||||
service2applications = Service2Application.filter_all(
|
||||
*Service2Application.convert({"service_uu_id__ilike": service_uu_id}),
|
||||
db=db_session,
|
||||
)
|
||||
already_events = [
|
||||
service_to_application.application_id for service_to_application in service2applications.data
|
||||
]
|
||||
Service2Application.set_session(db_session)
|
||||
service2applications = Service2Application.query.filter(*Service2Application.convert({"service_uu_id__ilike": service_uu_id})).all()
|
||||
already_events = [service_to_application.application_id for service_to_application in service2applications]
|
||||
if list_options.query:
|
||||
applications_list = Applications.filter_all(
|
||||
*Applications.convert(list_options.query), Applications.id.not_in(already_events), db=db_session
|
||||
)
|
||||
applications_list = Applications.query.filter(*Applications.convert(list_options.query), Applications.id.not_in(already_events))
|
||||
else:
|
||||
applications_list = Applications.filter_all(Applications.id.not_in(already_events), db=db_session)
|
||||
applications_list = Applications.query.filter(Applications.id.not_in(already_events))
|
||||
pagination = Pagination(data=applications_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(data=applications_list, pagination=pagination)
|
||||
@@ -167,21 +162,15 @@ def application_list_appended_callable(list_options: PaginateOnly):
|
||||
}
|
||||
list_options.query.pop("service_uu_id__ilike", None)
|
||||
list_options.query.pop("service_uu_id", None)
|
||||
|
||||
with Applications.new_session() as db_session:
|
||||
service2applications = Service2Application.filter_all(
|
||||
*Service2Application.convert({"service_uu_id__ilike": service_uu_id}),
|
||||
db=db_session,
|
||||
)
|
||||
already_events = [
|
||||
service_to_application.application_id for service_to_application in service2applications.data
|
||||
]
|
||||
with Service2Application.new_session() as db_session:
|
||||
Service2Application.set_session(db_session)
|
||||
Applications.set_session(db_session)
|
||||
service2applications = Service2Application.query.filter(*Service2Application.convert({"service_uu_id__ilike": service_uu_id})).all()
|
||||
already_events = [service_to_application.application_id for service_to_application in service2applications]
|
||||
if list_options.query:
|
||||
applications_list = Applications.filter_all(
|
||||
*Applications.convert(list_options.query), Applications.id.in_(already_events), db=db_session
|
||||
)
|
||||
applications_list = Applications.query.filter(*Applications.convert(list_options.query), Applications.id.in_(already_events))
|
||||
else:
|
||||
applications_list = Applications.filter_all(Applications.id.in_(already_events), db=db_session)
|
||||
applications_list = Applications.query.filter(Applications.id.in_(already_events))
|
||||
pagination = Pagination(data=applications_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(data=applications_list, pagination=pagination)
|
||||
@@ -197,13 +186,10 @@ def application_create_callable(data: Any):
|
||||
"""
|
||||
with Applications.new_session() as db_session:
|
||||
created_application_dict = data.model_dump()
|
||||
created_application = Applications.find_or_create(
|
||||
db=db_session,
|
||||
include_args=[Applications.application_for, Applications.application_code, Applications.site_url],
|
||||
**created_application_dict,
|
||||
)
|
||||
if created_application.meta_data.created:
|
||||
created_application.save(db=db_session)
|
||||
Applications.set_session(db_session)
|
||||
created_application = Applications.create(**created_application_dict)
|
||||
if created_application:
|
||||
created_application.save()
|
||||
return {
|
||||
"completed": True,
|
||||
"message": "MSG0001-INSERT",
|
||||
@@ -224,22 +210,16 @@ def application_update_callable(data: Any, uu_id: str):
|
||||
Update an existing application
|
||||
"""
|
||||
with Applications.new_session() as db_session:
|
||||
updated_application_dict = data.model_dump(
|
||||
exclude_unset=True, exclude_none=True
|
||||
)
|
||||
found_application = Applications.filter_one(
|
||||
Applications.uu_id == uu_id, db=db_session
|
||||
).data
|
||||
updated_application_dict = data.model_dump(exclude_unset=True, exclude_none=True)
|
||||
found_application = Applications.query.filter(Applications.uu_id == uu_id).first()
|
||||
if not found_application:
|
||||
return {
|
||||
"completed": False,
|
||||
"message": "MSG0002-FOUND",
|
||||
"data": found_application,
|
||||
}
|
||||
updated_application = found_application.update(
|
||||
db=db_session, **updated_application_dict
|
||||
)
|
||||
updated_application.save(db_session)
|
||||
updated_application = found_application.update(**updated_application_dict)
|
||||
updated_application.save()
|
||||
if updated_application.meta_data.updated:
|
||||
return {
|
||||
"completed": True,
|
||||
@@ -261,23 +241,32 @@ def application_register_service_callable(data: Any):
|
||||
Register an application to a service
|
||||
"""
|
||||
with Applications.new_session() as db_session:
|
||||
event = Applications.filter_one_system(Applications.uu_id == data.application_uu_id, db=db_session)
|
||||
if not event.data:
|
||||
Applications.set_session(db_session)
|
||||
event = Applications.query.filter(Applications.uu_id == data.application_uu_id).first()
|
||||
if not event:
|
||||
return {
|
||||
"message": "MSG0003-NOT-FOUND",
|
||||
"data": data.model_dump(),
|
||||
"completed": False,
|
||||
}
|
||||
service = Services.filter_one_system(Services.uu_id == data.service_uu_id, db=db_session)
|
||||
if not service.data:
|
||||
service = Services.query.filter(Services.uu_id == data.service_uu_id).first()
|
||||
if not service:
|
||||
return {
|
||||
"message": "MSG0003-NOT-FOUND",
|
||||
"data": data.model_dump(),
|
||||
"completed": False,
|
||||
}
|
||||
service_to_application = Service2Application.find_or_create(
|
||||
db=db_session,
|
||||
include_args=[Service2Application.service_uu_id, Service2Application.application_uu_id],
|
||||
service_to_application = Service2Application.query.filter(
|
||||
Service2Application.service_id == service.data.id,
|
||||
Service2Application.application_id == event.data.id,
|
||||
).first()
|
||||
if service_to_application:
|
||||
return {
|
||||
"message": "MSG0003-ALREADY-FOUND",
|
||||
"data": data.model_dump(),
|
||||
"completed": False,
|
||||
}
|
||||
service_to_application = Service2Application.create(
|
||||
service_id=service.data.id,
|
||||
service_uu_id=str(service.data.uu_id),
|
||||
application_id=event.data.id,
|
||||
@@ -286,13 +275,7 @@ def application_register_service_callable(data: Any):
|
||||
site_url=event.data.site_url,
|
||||
is_confirmed=True,
|
||||
)
|
||||
if not service_to_application.meta_data.created:
|
||||
return {
|
||||
"message": "MSG0003-ALREADY-FOUND",
|
||||
"data": data.model_dump(),
|
||||
"completed": False,
|
||||
}
|
||||
service_to_application.save(db=db_session)
|
||||
service_to_application.save()
|
||||
return {
|
||||
"message": "MSG0003-REGISTER",
|
||||
"data": data.model_dump(),
|
||||
@@ -308,26 +291,26 @@ def application_unregister_service_callable(data: Any):
|
||||
Unregister an application from a service
|
||||
"""
|
||||
with Applications.new_session() as db_session:
|
||||
application = Applications.filter_one_system(Applications.uu_id == data.application_uu_id, db=db_session)
|
||||
if not application.data:
|
||||
Applications.set_session(db_session)
|
||||
application = Applications.query.filter(Applications.uu_id == data.application_uu_id).first()
|
||||
if not application:
|
||||
return {
|
||||
"message": "MSG0003-NOT-FOUND",
|
||||
"data": data.model_dump(),
|
||||
"completed": False,
|
||||
}
|
||||
service = Services.filter_one_system(Services.uu_id == data.service_uu_id, db=db_session)
|
||||
if not service.data:
|
||||
service = Services.query.filter(Services.uu_id == data.service_uu_id).first()
|
||||
if not service:
|
||||
return {
|
||||
"message": "MSG0003-NOT-FOUND",
|
||||
"data": data.model_dump(),
|
||||
"completed": False,
|
||||
}
|
||||
service_to_application = Service2Application.filter_one_system(
|
||||
service_to_application = Service2Application.query.filter(
|
||||
Service2Application.service_id == service.data.id,
|
||||
Service2Application.application_id == application.data.id,
|
||||
db=db_session,
|
||||
)
|
||||
if not service_to_application.data:
|
||||
).first()
|
||||
if not service_to_application:
|
||||
return {
|
||||
"message": "MSG0003-NOT-FOUND",
|
||||
"data": data.model_dump(),
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
from api_initializer.event_clusters import EventCluster, RouterCluster
|
||||
from index import endpoints_index
|
||||
from .supers_events import (
|
||||
SuperServiceListEvent,
|
||||
SuperServiceCreateEvent,
|
||||
SuperServiceUpdateEvent,
|
||||
SuperServiceDeleteEvent,
|
||||
)
|
||||
|
||||
ServicesRouterCluster = RouterCluster(name="ServicesRouterCluster")
|
||||
|
||||
ServicesEventClusterList = EventCluster(name="ServicesList", endpoint_uu_id=endpoints_index["ServicesList"])
|
||||
ServicesEventClusterList.add_event(SuperServiceListEvent)
|
||||
|
||||
ServicesEventClusterCreate = EventCluster(name="ServicesCreate", endpoint_uu_id=endpoints_index["ServicesCreate"])
|
||||
ServicesEventClusterCreate.add_event(SuperServiceCreateEvent)
|
||||
|
||||
ServicesEventClusterUpdate = EventCluster(name="ServicesUpdate", endpoint_uu_id=endpoints_index["ServicesUpdate"])
|
||||
ServicesEventClusterUpdate.add_event(SuperServiceUpdateEvent)
|
||||
|
||||
ServicesEventClusterDelete = EventCluster(name="ServicesDelete", endpoint_uu_id=endpoints_index["ServicesDelete"])
|
||||
ServicesEventClusterDelete.add_event(SuperServiceDeleteEvent)
|
||||
|
||||
ServicesRouterCluster.set_event_cluster(ServicesEventClusterList)
|
||||
ServicesRouterCluster.set_event_cluster(ServicesEventClusterCreate)
|
||||
ServicesRouterCluster.set_event_cluster(ServicesEventClusterUpdate)
|
||||
ServicesRouterCluster.set_event_cluster(ServicesEventClusterDelete)
|
||||
@@ -0,0 +1,105 @@
|
||||
from typing import Any
|
||||
|
||||
from api_validations.defaults.validations import CommonHeaders
|
||||
from api_initializer.event_clusters import Event
|
||||
from api_validations.response import (
|
||||
PaginateOnly,
|
||||
Pagination,
|
||||
PaginationResult,
|
||||
PostgresResponseSingle,
|
||||
PostgresResponse,
|
||||
EndpointResponse
|
||||
)
|
||||
from schemas import (
|
||||
Events,
|
||||
Event2Employee,
|
||||
Event2Occupant,
|
||||
Event2EmployeeExtra,
|
||||
Event2OccupantExtra,
|
||||
Service2Events,
|
||||
Services,
|
||||
)
|
||||
|
||||
# List services endpoint
|
||||
SuperServiceListEvent = Event(
|
||||
name="super_service_list",
|
||||
key="ea24f5e6-279a-47e7-a5bd-8a5c1bd72d05",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Super Users List available events endpoint",
|
||||
)
|
||||
|
||||
# Create service endpoint
|
||||
SuperServiceCreateEvent = Event(
|
||||
name="super_service_create",
|
||||
key="086051f4-f1ec-4d56-b706-09ce53d5e66c",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Super Users Create service endpoint",
|
||||
)
|
||||
|
||||
# Update service endpoint
|
||||
SuperServiceUpdateEvent = Event(
|
||||
name="super_service_update",
|
||||
key="267956e5-32b7-4b60-ab75-3b56b935d5c1",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Super Users Update service endpoint",
|
||||
)
|
||||
|
||||
# Delete service endpoint
|
||||
SuperServiceDeleteEvent = Event(
|
||||
name="super_service_delete",
|
||||
key="6c333122-272e-4690-9d71-7f5e14cc64c8",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Super Users Delete service endpoint",
|
||||
)
|
||||
|
||||
|
||||
def super_service_list_callable(list_options: PaginateOnly, headers: CommonHeaders):
|
||||
"""List available events with pagination and filtering options"""
|
||||
return {
|
||||
"message": "MSG0003-LIST",
|
||||
"data": None,
|
||||
"completed": True,
|
||||
}
|
||||
|
||||
|
||||
SuperServiceListEvent.event_callable = super_service_list_callable
|
||||
|
||||
|
||||
def super_service_create_callable(data: Any, headers: CommonHeaders):
|
||||
"""Create service"""
|
||||
return {
|
||||
"message": "MSG0003-CREATE",
|
||||
"data": None,
|
||||
"completed": True,
|
||||
}
|
||||
|
||||
|
||||
SuperServiceCreateEvent.event_callable = super_service_create_callable
|
||||
|
||||
|
||||
def super_service_update_callable(data: Any, headers: CommonHeaders):
|
||||
"""Update service"""
|
||||
return {
|
||||
"message": "MSG0003-UPDATE",
|
||||
"data": None,
|
||||
"completed": True,
|
||||
}
|
||||
|
||||
|
||||
SuperServiceUpdateEvent.event_callable = super_service_update_callable
|
||||
|
||||
|
||||
def super_service_delete_callable(data: Any, headers: CommonHeaders):
|
||||
"""Delete service"""
|
||||
return {
|
||||
"message": "MSG0003-DELETE",
|
||||
"data": None,
|
||||
"completed": True,
|
||||
}
|
||||
|
||||
|
||||
SuperServiceDeleteEvent.event_callable = super_service_delete_callable
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
endpoints_index: dict = {
|
||||
"AccountRecordsAll": "d538deb4-38f4-4913-a1af-bbef14cf6873",
|
||||
"AccountRecordsMonthly": "c0f5ccb1-1e56-4653-af13-ec0bf5e6aa51",
|
||||
@@ -16,4 +17,8 @@ endpoints_index: dict = {
|
||||
"ApplicationUpdate": "83281757-696a-41ed-9706-e145ac54c3a9",
|
||||
"ApplicationBindEmployee": "80427237-5ab6-4d17-8084-cdb87bda22a3",
|
||||
"ApplicationBindOccupant": "ae0fb101-cb13-47ab-86bd-233a5dbef269",
|
||||
}
|
||||
"ServicesList": "7af16881-2c0f-463f-859f-7aca475e65eb",
|
||||
"ServicesCreate": "effca319-2074-4862-bb80-dde77f0e8407",
|
||||
"ServicesUpdate": "24dc83e9-c159-4bb3-8982-a8adf6555029",
|
||||
"ServicesDelete": "f4c9b2c4-d18a-43c6-abf9-030f71a1c381",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user