event and service sendpoints added
This commit is contained in:
@@ -5,9 +5,7 @@ from ApiControllers.providers.token_provider import TokenProvider
|
||||
|
||||
from Controllers.Postgres.pagination import PaginateOnly, Pagination, PaginationResult
|
||||
from Controllers.Postgres.response import EndpointResponse
|
||||
from Schemas import (
|
||||
Applications
|
||||
)
|
||||
from Schemas import Applications
|
||||
from Validations.application.validations import (
|
||||
RequestApplication,
|
||||
)
|
||||
@@ -71,7 +69,7 @@ def application_create_route(
|
||||
Applications.application_code == data.application_code,
|
||||
Applications.site_url == data.site_url,
|
||||
]
|
||||
**created_application_dict
|
||||
** created_application_dict,
|
||||
)
|
||||
if created_application.meta_data.created:
|
||||
return EndpointResponse(
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from ApiControllers.abstracts.default_validations import CommonHeaders
|
||||
from ApiControllers.providers.token_provider import TokenProvider
|
||||
|
||||
from Controllers.Postgres.pagination import PaginateOnly, Pagination, PaginationResult
|
||||
from Controllers.Postgres.response import EndpointResponse
|
||||
from Validations.service_endpoints.validations import Event2Employee, Event2Occupant
|
||||
|
||||
# Create API router
|
||||
event_endpoint_route = APIRouter(prefix="/events", tags=["Event Actions"])
|
||||
|
||||
|
||||
@event_endpoint_route.post(
|
||||
path="/list",
|
||||
description="List events endpoint",
|
||||
operation_id="0659d5e4-671f-466c-a84f-47a1290a6f0d",
|
||||
)
|
||||
def event_list_route(
|
||||
data: PaginateOnly,
|
||||
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
|
||||
):
|
||||
"""
|
||||
List events with pagination and filtering options
|
||||
"""
|
||||
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 = EventEndpointRouterCluster.get_event_cluster("EventList")
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(data=data)
|
||||
|
||||
|
||||
@event_endpoint_route.post(
|
||||
path="/bind/employee",
|
||||
description="Bind event to employee endpoint",
|
||||
operation_id="",
|
||||
)
|
||||
def event_bind_employee_route(
|
||||
data: Event2Employee,
|
||||
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
|
||||
):
|
||||
"""
|
||||
Bind event to employee
|
||||
"""
|
||||
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 = EventEndpointRouterCluster.get_event_cluster("EventBindEmployee")
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(data=data)
|
||||
|
||||
|
||||
@event_endpoint_route.post(
|
||||
path="/bind/occupant",
|
||||
description="Bind event to occupant endpoint",
|
||||
operation_id="",
|
||||
)
|
||||
def event_bind_occupant_route(
|
||||
data: Event2Occupant,
|
||||
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
|
||||
):
|
||||
"""
|
||||
Bind event to occupant
|
||||
"""
|
||||
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 = EventEndpointRouterCluster.get_event_cluster("EventBindOccupant")
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(data=data)
|
||||
@@ -0,0 +1,31 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from ApiControllers.abstracts.default_validations import CommonHeaders
|
||||
from ApiControllers.providers.token_provider import TokenProvider
|
||||
|
||||
from Controllers.Postgres.pagination import PaginateOnly, Pagination, PaginationResult
|
||||
from Controllers.Postgres.response import EndpointResponse
|
||||
|
||||
|
||||
# Create API router
|
||||
service_endpoint_route = APIRouter(prefix="/service", tags=["Service Actions"])
|
||||
|
||||
|
||||
@service_endpoint_route.post(
|
||||
path="/list",
|
||||
description="List services endpoint",
|
||||
operation_id="f4e4d332-70b1-4121-9fcc-a08850b72aaa",
|
||||
)
|
||||
def service_list_route(
|
||||
data: PaginateOnly,
|
||||
headers: CommonHeaders = Depends(CommonHeaders.as_dependency),
|
||||
):
|
||||
"""
|
||||
List services with pagination and filtering options
|
||||
"""
|
||||
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 = ServiceEndpointRouterCluster.get_event_cluster("ServiceList")
|
||||
event_cluster_matched = FoundCluster.match_event(event_key=event_key)
|
||||
return event_cluster_matched.event_callable(data=data)
|
||||
@@ -0,0 +1,26 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
|
||||
from ApiControllers.abstracts.default_validations import CommonHeaders
|
||||
from ApiControllers.providers.token_provider import TokenProvider
|
||||
|
||||
from Controllers.Postgres.pagination import PaginateOnly, Pagination, PaginationResult
|
||||
from Controllers.Postgres.response import EndpointResponse
|
||||
from Schemas import (
|
||||
Services,
|
||||
Employees,
|
||||
Event2Employee,
|
||||
Users,
|
||||
Events,
|
||||
Service2Events,
|
||||
Applications,
|
||||
Application2Employee,
|
||||
Application2Occupant,
|
||||
)
|
||||
from Validations.application.validations import (
|
||||
RequestApplication,
|
||||
)
|
||||
|
||||
# Create API router
|
||||
service_management_route = APIRouter(
|
||||
prefix="/managements/service", tags=["Service Management"]
|
||||
)
|
||||
@@ -1,3 +1 @@
|
||||
|
||||
|
||||
__all__ = []
|
||||
__all__ = []
|
||||
|
||||
27
ApiServices/ManagementService/Events/application/cluster.py
Normal file
27
ApiServices/ManagementService/Events/application/cluster.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from ApiControllers.abstracts.event_clusters import EventCluster, RouterCluster
|
||||
from .supers_events import (
|
||||
SuperUsersListEvent,
|
||||
SuperUsersCreateEvent,
|
||||
SuperUsersUpdateEvent,
|
||||
)
|
||||
|
||||
UserRouterCluster = RouterCluster(name="UserRouterCluster")
|
||||
|
||||
UserEventClusterList = EventCluster(
|
||||
name="UserList", endpoint_uu_id="5bc09312-d3f2-4f47-baba-17c928706da8"
|
||||
)
|
||||
UserEventClusterList.add_event(SuperUsersListEvent)
|
||||
|
||||
UserEventClusterCreate = EventCluster(
|
||||
name="UserCreate", endpoint_uu_id="08d4b572-1584-47bb-aa42-8d068e5514e7"
|
||||
)
|
||||
UserEventClusterCreate.add_event(SuperUsersCreateEvent)
|
||||
|
||||
UserEventClusterUpdate = EventCluster(
|
||||
name="UserUpdate", endpoint_uu_id="b641236a-928d-4f19-a1d2-5edf611d1e56"
|
||||
)
|
||||
UserEventClusterUpdate.add_event(SuperUsersUpdateEvent)
|
||||
|
||||
UserRouterCluster.set_event_cluster(UserEventClusterList)
|
||||
UserRouterCluster.set_event_cluster(UserEventClusterCreate)
|
||||
UserRouterCluster.set_event_cluster(UserEventClusterUpdate)
|
||||
@@ -0,0 +1,94 @@
|
||||
from ApiControllers.abstracts.event_clusters import Event
|
||||
from Controllers.Postgres.pagination import Pagination, PaginationResult, PaginateOnly
|
||||
from Controllers.Postgres.response import EndpointResponse
|
||||
from Schemas import Users
|
||||
|
||||
|
||||
# List endpoint
|
||||
SuperUsersListEvent = Event(
|
||||
name="supers_users_list",
|
||||
key="341b394f-9f11-4abb-99e7-4b27fa6bf012",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="List events of users endpoint",
|
||||
)
|
||||
|
||||
# Create endpoint
|
||||
SuperUsersCreateEvent = Event(
|
||||
name="supers_users_create",
|
||||
key="4e7e189e-e015-4ff8-902d-60138cbc77a6",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Create events of users endpoint",
|
||||
)
|
||||
|
||||
# Update endpoint
|
||||
SuperUsersUpdateEvent = Event(
|
||||
name="supers_users_update",
|
||||
key="efa4aa4a-d414-4391-91ee-97eb617b7755",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
response_validator=None, # TODO: Add response validator
|
||||
description="Update events of users endpoint",
|
||||
)
|
||||
|
||||
|
||||
def supers_users_list_callable(list_options: PaginateOnly):
|
||||
"""
|
||||
Example callable method
|
||||
"""
|
||||
list_options = PaginateOnly(**list_options.model_dump())
|
||||
with Users.new_session() as db_session:
|
||||
if list_options.query:
|
||||
users_list = Users.filter_all(
|
||||
*Users.convert(list_options.query), db=db_session
|
||||
)
|
||||
else:
|
||||
users_list = Users.filter_all(db=db_session)
|
||||
pagination = Pagination(data=users_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(
|
||||
data=users_list,
|
||||
pagination=pagination,
|
||||
# response_model="",
|
||||
).pagination.as_dict
|
||||
return EndpointResponse(
|
||||
message="MSG0003-LIST",
|
||||
pagination_result=pagination_result,
|
||||
).response
|
||||
|
||||
|
||||
SuperUsersListEvent.event_callable = supers_users_list_callable
|
||||
|
||||
|
||||
def supers_users_create_callable():
|
||||
"""
|
||||
Example callable method
|
||||
"""
|
||||
return {
|
||||
"completed": True,
|
||||
"message": "Example callable method 2",
|
||||
"info": {
|
||||
"host": "example_host",
|
||||
"user_agent": "example_user_agent",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
SuperUsersCreateEvent.event_callable = supers_users_create_callable
|
||||
|
||||
|
||||
def supers_users_update_callable():
|
||||
"""
|
||||
Example callable method
|
||||
"""
|
||||
return {
|
||||
"completed": True,
|
||||
"message": "Example callable method 2",
|
||||
"info": {
|
||||
"host": "example_host",
|
||||
"user_agent": "example_user_agent",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
SuperUsersUpdateEvent.event_callable = supers_users_update_callable
|
||||
@@ -0,0 +1,11 @@
|
||||
from ApiControllers.abstracts.event_clusters import EventCluster, RouterCluster
|
||||
from .supers_events import (
|
||||
ServiceEndpointListEvent,
|
||||
)
|
||||
|
||||
ServiceEndpointRouterCluster = RouterCluster(name="ServiceEndpointRouterCluster")
|
||||
ServiceEndpointEventClusterList = EventCluster(
|
||||
name="ServiceList", endpoint_uu_id="82ef3444-a26a-499d-8c77-ca2e95d6ceb9"
|
||||
)
|
||||
ServiceEndpointEventClusterList.add_event(ServiceEndpointListEvent)
|
||||
ServiceEndpointRouterCluster.set_event_cluster(ServiceEndpointEventClusterList)
|
||||
@@ -0,0 +1,42 @@
|
||||
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
|
||||
|
||||
|
||||
# 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="List services endpoint",
|
||||
)
|
||||
|
||||
|
||||
def service_endpoint_list_callable(list_options: PaginateOnly):
|
||||
"""
|
||||
Example callable method
|
||||
"""
|
||||
list_options = PaginateOnly(**list_options.model_dump())
|
||||
with Services.new_session() as db_session:
|
||||
if list_options.query:
|
||||
services_list = Services.filter_all(
|
||||
*Services.convert(list_options.query), db=db_session
|
||||
)
|
||||
else:
|
||||
services_list = Services.filter_all(db=db_session)
|
||||
pagination = Pagination(data=services_list)
|
||||
pagination.change(**list_options.model_dump())
|
||||
pagination_result = PaginationResult(
|
||||
data=services_list,
|
||||
pagination=pagination,
|
||||
# response_model="",
|
||||
).pagination.as_dict
|
||||
return EndpointResponse(
|
||||
message="MSG0003-LIST",
|
||||
pagination_result=pagination_result,
|
||||
).response
|
||||
|
||||
|
||||
ServiceEndpointListEvent.event_callable = service_endpoint_list_callable
|
||||
@@ -1,12 +1,15 @@
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class RequestApplication(BaseModel):
|
||||
"""Base model for application data"""
|
||||
|
||||
name: str = Field(..., description="Application name")
|
||||
application_code: str = Field(..., description="Unique application code")
|
||||
site_url: str = Field(..., description="Application site URL")
|
||||
application_type: str = Field(..., description="Application type (info, Dash, Admin)")
|
||||
application_type: str = Field(
|
||||
..., description="Application type (info, Dash, Admin)"
|
||||
)
|
||||
application_for: str = Field(..., description="Application for (EMP, OCC)")
|
||||
description: Optional[str] = Field(None, description="Application description")
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
class Event2Employee:
|
||||
pass
|
||||
|
||||
|
||||
class Event2Occupant:
|
||||
pass
|
||||
Reference in New Issue
Block a user