latest version of apis event and cahce ablitites added
This commit is contained in:
0
Events/AllEvents/__init__.py
Normal file
0
Events/AllEvents/__init__.py
Normal file
9
Events/AllEvents/authentication/__init__.py
Normal file
9
Events/AllEvents/authentication/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
Authentication package initialization.
|
||||
"""
|
||||
|
||||
from .auth.cluster import AuthCluster
|
||||
|
||||
__all__ = [
|
||||
"AuthCluster",
|
||||
]
|
||||
200
Events/AllEvents/authentication/auth/api_events.py
Normal file
200
Events/AllEvents/authentication/auth/api_events.py
Normal file
@@ -0,0 +1,200 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
SelectRequestLanguageModel,
|
||||
)
|
||||
|
||||
from .models import AuthenticationRequestModels, AuthenticationResponseModels
|
||||
from .function_handlers import AuthenticationFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
authentication_login_super_user_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=AuthenticationRequestModels.LoginSuperUserRequestModel,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
statics="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
authentication_login_super_user_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_login_with_domain_and_creds
|
||||
)
|
||||
|
||||
|
||||
# Auth Select Company or Occupant Type
|
||||
authentication_select_super_user_event = Event(
|
||||
name="authentication_select_super_user_event",
|
||||
key="f951ae1a-7950-4eab-ae2d-5bd9c2d21173",
|
||||
request_validator=AuthenticationRequestModels.SelectCompanyOrOccupantTypeSuperUserRequestModel,
|
||||
language_models=[SelectRequestLanguageModel],
|
||||
statics="LOGIN_SELECT",
|
||||
description="Select company or occupant type super user",
|
||||
)
|
||||
|
||||
|
||||
authentication_select_super_user_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_select_company_or_occupant_type
|
||||
)
|
||||
|
||||
|
||||
# Check Token Validity
|
||||
authentication_check_token_event = Event(
|
||||
name="authentication_check_token_event",
|
||||
key="b6e3d1e2-4f9c-5c1g-9d8e-7e5f6f5e5d5f",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Check if token is valid",
|
||||
)
|
||||
|
||||
|
||||
authentication_check_token_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_check_token_is_valid
|
||||
)
|
||||
|
||||
|
||||
# Refresh User Info
|
||||
authentication_refresh_user_info_event = Event(
|
||||
name="authentication_refresh_user_info_event",
|
||||
key="c7f4e2f3-5g0d-6d2h-0e9f-8f6g7g6f6e6g",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Refresh user information",
|
||||
)
|
||||
|
||||
|
||||
authentication_refresh_user_info_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_access_token_user_info
|
||||
)
|
||||
|
||||
|
||||
# Change Password
|
||||
authentication_change_password_event = Event(
|
||||
name="authentication_change_password_event",
|
||||
key="d8g5f3g4-6h1e-7e3i-1f0g-9g7h8h7g7f7h",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Change user password",
|
||||
)
|
||||
|
||||
|
||||
authentication_change_password_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_change_password
|
||||
)
|
||||
|
||||
|
||||
# Create Password
|
||||
authentication_create_password_event = Event(
|
||||
name="authentication_create_password_event",
|
||||
key="e9h6g4h5-7i2f-8f4j-2g1h-0h8i9i8h8g8i",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Create new password",
|
||||
)
|
||||
|
||||
|
||||
authentication_create_password_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_create_password
|
||||
)
|
||||
|
||||
|
||||
# Disconnect User
|
||||
authentication_disconnect_user_event = Event(
|
||||
name="authentication_disconnect_user_event",
|
||||
key="f0i7h5i6-8j3g-9g5k-3h2i-1i9j0j9i9h9j",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Disconnect all user sessions",
|
||||
)
|
||||
|
||||
|
||||
authentication_disconnect_user_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_disconnect_user
|
||||
)
|
||||
|
||||
|
||||
# Logout User
|
||||
authentication_logout_user_event = Event(
|
||||
name="authentication_logout_user_event",
|
||||
key="g1j8i6j7-9k4h-0h6l-4i3j-2j0k1k0j0i0k",
|
||||
request_validator=AuthenticationRequestModels.LogoutRequestModel,
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Logout user session",
|
||||
)
|
||||
|
||||
|
||||
authentication_logout_user_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_logout_user
|
||||
)
|
||||
|
||||
|
||||
# Refresh Token
|
||||
authentication_refresher_token_event = Event(
|
||||
name="authentication_refresher_token_event",
|
||||
key="h2k9j7k8-0l5i-1i7m-5j4k-3k1l2l1k1j1l",
|
||||
request_validator=AuthenticationRequestModels.RefresherRequestModel, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None,
|
||||
description="Refresh authentication token",
|
||||
)
|
||||
|
||||
|
||||
authentication_refresher_token_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_refresher_token
|
||||
)
|
||||
|
||||
|
||||
# Forgot Password
|
||||
authentication_forgot_password_event = Event(
|
||||
name="authentication_forgot_password_event",
|
||||
key="i3l0k8l9-1m6j-2j8n-6k5l-4l2m3m2l2k2m",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Request password reset",
|
||||
)
|
||||
|
||||
|
||||
authentication_forgot_password_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_forgot_password
|
||||
)
|
||||
|
||||
|
||||
# Reset Password
|
||||
authentication_reset_password_event = Event(
|
||||
name="authentication_reset_password_event",
|
||||
key="j4m1l9m0-2n7k-3k9o-7l6m-5m3n4n3m3l3n",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Reset user password",
|
||||
)
|
||||
|
||||
|
||||
authentication_reset_password_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_reset_password
|
||||
)
|
||||
|
||||
|
||||
# Download Avatar
|
||||
authentication_download_avatar_event = Event(
|
||||
name="authentication_download_avatar_event",
|
||||
key="k5n2m0n1-3o8l-4l0p-8m7n-6n4o5o4n4m4o",
|
||||
request_validator=None, # TODO: Add request validator
|
||||
language_models=[],
|
||||
# response_validator=None, # TODO: Add response validator
|
||||
description="Download user avatar and profile info",
|
||||
)
|
||||
|
||||
|
||||
authentication_download_avatar_event.endpoint_callable = (
|
||||
AuthenticationFunctions.authentication_download_avatar
|
||||
)
|
||||
383
Events/AllEvents/authentication/auth/auth.py
Normal file
383
Events/AllEvents/authentication/auth/auth.py
Normal file
@@ -0,0 +1,383 @@
|
||||
"""
|
||||
Authentication related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
from fastapi import Request
|
||||
|
||||
from ApiLayers.Middleware import MiddlewareModule
|
||||
from Events.Engine.abstract_class import MethodToEvent
|
||||
from Events.base_request_model import EndpointBaseRequestModel, ContextRetrievers
|
||||
|
||||
from .api_events import (
|
||||
authentication_login_super_user_event,
|
||||
authentication_select_super_user_event,
|
||||
authentication_check_token_event,
|
||||
authentication_refresh_user_info_event,
|
||||
authentication_change_password_event,
|
||||
authentication_create_password_event,
|
||||
authentication_disconnect_user_event,
|
||||
authentication_logout_user_event,
|
||||
authentication_refresher_token_event,
|
||||
authentication_forgot_password_event,
|
||||
authentication_reset_password_event,
|
||||
authentication_download_avatar_event,
|
||||
)
|
||||
from .function_handlers import AuthenticationFunctions
|
||||
|
||||
|
||||
AuthenticationLoginEventMethods = MethodToEvent(
|
||||
name="AuthenticationLoginEventMethods",
|
||||
events={
|
||||
authentication_login_super_user_event.key: authentication_login_super_user_event,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/login",
|
||||
method="POST",
|
||||
summary="Login via domain and access key : [email] | [phone]",
|
||||
description="Login to the system via domain, access key : [email] | [phone]",
|
||||
)
|
||||
|
||||
|
||||
def authentication_login_with_domain_and_creds_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
event_2_catch = AuthenticationLoginEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_login_super_user_event.key}"
|
||||
)
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
return event_2_catch.endpoint_callable(request=request, data=data)
|
||||
|
||||
|
||||
AuthenticationLoginEventMethods.endpoint_callable = (
|
||||
authentication_login_with_domain_and_creds_endpoint
|
||||
)
|
||||
|
||||
|
||||
AuthenticationSelectEventMethods = MethodToEvent(
|
||||
name="AuthenticationSelectEventMethods",
|
||||
events={
|
||||
authentication_select_super_user_event.key: authentication_select_super_user_event,
|
||||
},
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/select",
|
||||
method="POST",
|
||||
summary="Select company or occupant type",
|
||||
description="Select company or occupant type",
|
||||
)
|
||||
|
||||
|
||||
def authentication_select_company_or_occupant_type(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Select company or occupant type.
|
||||
"""
|
||||
context_retriever = ContextRetrievers(
|
||||
func=authentication_select_company_or_occupant_type
|
||||
)
|
||||
function = AuthenticationSelectEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_select_super_user_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
data_model = None
|
||||
if context_retriever.token.is_employee:
|
||||
data_model = function.REQUEST_VALIDATOR.get("EmployeeSelection", None)(
|
||||
**data.data
|
||||
)
|
||||
elif context_retriever.token.is_occupant:
|
||||
data_model = function.REQUEST_VALIDATOR.get("OccupantSelection", None)(
|
||||
**data.data
|
||||
)
|
||||
return function.endpoint_callable(data=data_model)
|
||||
|
||||
|
||||
AuthenticationSelectEventMethods.endpoint_callable = (
|
||||
authentication_select_company_or_occupant_type
|
||||
)
|
||||
|
||||
|
||||
AuthenticationCheckTokenEventMethods = MethodToEvent(
|
||||
name="AuthenticationCheckTokenEventMethods",
|
||||
events={authentication_check_token_event.key: authentication_check_token_event},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/check-token",
|
||||
method="POST",
|
||||
summary="Check if token is valid",
|
||||
description="Check if access token is valid for user",
|
||||
)
|
||||
|
||||
|
||||
def authentication_check_token_is_valid(request: Request):
|
||||
context_retriever = ContextRetrievers(func=authentication_check_token_is_valid)
|
||||
function = AuthenticationCheckTokenEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_check_token_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable()
|
||||
|
||||
|
||||
AuthenticationCheckTokenEventMethods.endpoint_callable = (
|
||||
authentication_check_token_is_valid
|
||||
)
|
||||
|
||||
|
||||
AuthenticationRefreshEventMethods = MethodToEvent(
|
||||
name="AuthenticationRefreshEventMethods",
|
||||
events={
|
||||
authentication_refresh_user_info_event.key: authentication_refresh_user_info_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/refresh",
|
||||
method="POST",
|
||||
summary="Refresh user info",
|
||||
description="Refresh user info using access token",
|
||||
)
|
||||
|
||||
|
||||
def authentication_refresh_user_info(request: Request):
|
||||
context_retriever = ContextRetrievers(func=authentication_refresh_user_info)
|
||||
function = AuthenticationRefreshEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_refresh_user_info_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable()
|
||||
|
||||
|
||||
AuthenticationRefreshEventMethods.endpoint_callable = authentication_refresh_user_info
|
||||
|
||||
|
||||
AuthenticationChangePasswordEventMethods = MethodToEvent(
|
||||
name="AuthenticationChangePasswordEventMethods",
|
||||
events={
|
||||
authentication_change_password_event.key: authentication_change_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/change-password",
|
||||
method="POST",
|
||||
summary="Change password",
|
||||
description="Change password with access token",
|
||||
)
|
||||
|
||||
|
||||
def authentication_change_password_event_callable(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
):
|
||||
context_retriever = ContextRetrievers(
|
||||
func=authentication_change_password_event_callable
|
||||
)
|
||||
function = AuthenticationChangePasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_change_password_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable(data=data)
|
||||
|
||||
|
||||
AuthenticationChangePasswordEventMethods.endpoint_callable = (
|
||||
authentication_change_password_event_callable
|
||||
)
|
||||
|
||||
AuthenticationCreatePasswordEventMethods = MethodToEvent(
|
||||
name="AuthenticationCreatePasswordEventMethods",
|
||||
events={
|
||||
authentication_create_password_event.key: authentication_create_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/create-password",
|
||||
method="POST",
|
||||
summary="Create password",
|
||||
description="Create password with password reset token requested via email",
|
||||
)
|
||||
|
||||
|
||||
def authentication_create_password(request: Request, data: EndpointBaseRequestModel):
|
||||
context_retriever = ContextRetrievers(func=authentication_create_password)
|
||||
function = AuthenticationCreatePasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_create_password_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable(data=data)
|
||||
|
||||
|
||||
AuthenticationCreatePasswordEventMethods.endpoint_callable = (
|
||||
authentication_create_password
|
||||
)
|
||||
|
||||
|
||||
AuthenticationDisconnectUserEventMethods = MethodToEvent(
|
||||
name="AuthenticationDisconnectUserEventMethods",
|
||||
events={
|
||||
authentication_disconnect_user_event.key: authentication_disconnect_user_event
|
||||
},
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/disconnect",
|
||||
method="POST",
|
||||
summary="Disconnect all sessions",
|
||||
description="Disconnect all sessions of user in access token",
|
||||
)
|
||||
|
||||
|
||||
def authentication_disconnect_user(request: Request):
|
||||
context_retriever = ContextRetrievers(func=authentication_disconnect_user)
|
||||
function = AuthenticationDisconnectUserEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_disconnect_user_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable()
|
||||
|
||||
|
||||
AuthenticationDisconnectUserEventMethods.endpoint_callable = (
|
||||
authentication_disconnect_user
|
||||
)
|
||||
|
||||
|
||||
AuthenticationLogoutEventMethods = MethodToEvent(
|
||||
name="AuthenticationLogoutEventMethods",
|
||||
events={authentication_logout_user_event.key: authentication_logout_user_event},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/logout",
|
||||
method="POST",
|
||||
summary="Logout user",
|
||||
description="Logout only single session of user which domain is provided",
|
||||
)
|
||||
|
||||
|
||||
def authentication_logout_user(request: Request, data: EndpointBaseRequestModel):
|
||||
context_retriever = ContextRetrievers(func=authentication_logout_user)
|
||||
function = AuthenticationLogoutEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_logout_user_event.key}"
|
||||
)
|
||||
validated_data = function.REQUEST_VALIDATOR(**data.data)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable(data=validated_data)
|
||||
|
||||
|
||||
AuthenticationLogoutEventMethods.endpoint_callable = authentication_logout_user
|
||||
|
||||
|
||||
AuthenticationRefreshTokenEventMethods = MethodToEvent(
|
||||
name="AuthenticationRefreshTokenEventMethods",
|
||||
events={
|
||||
authentication_refresher_token_event.key: authentication_refresher_token_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[],
|
||||
url="/refresh-token",
|
||||
method="POST",
|
||||
summary="Refresh token",
|
||||
description="Refresh access token with refresher token",
|
||||
)
|
||||
|
||||
|
||||
def authentication_refresher_token(request: Request, data: EndpointBaseRequestModel):
|
||||
function = AuthenticationRefreshTokenEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_refresher_token_event.key}"
|
||||
)
|
||||
validated_data = function.REQUEST_VALIDATOR(**data.data)
|
||||
return function.endpoint_callable(request=request, data=validated_data)
|
||||
|
||||
|
||||
AuthenticationRefreshTokenEventMethods.endpoint_callable = (
|
||||
authentication_refresher_token
|
||||
)
|
||||
|
||||
|
||||
AuthenticationForgotPasswordEventMethods = MethodToEvent(
|
||||
name="AuthenticationForgotPasswordEventMethods",
|
||||
events={
|
||||
authentication_forgot_password_event.key: authentication_forgot_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
url="/forgot-password",
|
||||
method="POST",
|
||||
summary="Request password reset",
|
||||
description="Send an email to user for a valid password reset token",
|
||||
)
|
||||
|
||||
|
||||
def authentication_forgot_password(request: Request, data: EndpointBaseRequestModel):
|
||||
context_retriever = ContextRetrievers(func=authentication_forgot_password)
|
||||
function = AuthenticationForgotPasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_forgot_password_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable(data=data)
|
||||
|
||||
|
||||
AuthenticationForgotPasswordEventMethods.endpoint_callable = (
|
||||
authentication_forgot_password
|
||||
)
|
||||
|
||||
|
||||
AuthenticationResetPasswordEventMethods = MethodToEvent(
|
||||
name="AuthenticationResetPasswordEventMethods",
|
||||
events={
|
||||
authentication_reset_password_event.key: authentication_reset_password_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/reset-password",
|
||||
method="POST",
|
||||
summary="Reset password",
|
||||
description="Reset user password",
|
||||
)
|
||||
|
||||
|
||||
def authentication_reset_password(request: Request, data: EndpointBaseRequestModel):
|
||||
context_retriever = ContextRetrievers(func=authentication_reset_password)
|
||||
function = AuthenticationResetPasswordEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_reset_password_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable(data=data.data)
|
||||
|
||||
|
||||
AuthenticationResetPasswordEventMethods.endpoint_callable = (
|
||||
authentication_reset_password
|
||||
)
|
||||
|
||||
|
||||
AuthenticationDownloadAvatarEventMethods = MethodToEvent(
|
||||
name="AuthenticationDownloadAvatarEventMethods",
|
||||
events={
|
||||
authentication_download_avatar_event.key: authentication_download_avatar_event
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[MiddlewareModule.auth_required],
|
||||
url="/download-avatar",
|
||||
method="POST",
|
||||
summary="Download avatar",
|
||||
description="Download avatar icon and profile info of user",
|
||||
)
|
||||
|
||||
|
||||
def authentication_download_avatar(request: Request):
|
||||
context_retriever = ContextRetrievers(func=authentication_download_avatar)
|
||||
function = AuthenticationDownloadAvatarEventMethods.retrieve_event(
|
||||
event_function_code=f"{authentication_download_avatar_event.key}"
|
||||
)
|
||||
AuthenticationFunctions.context_retriever = context_retriever
|
||||
return function.endpoint_callable()
|
||||
|
||||
|
||||
AuthenticationDownloadAvatarEventMethods.endpoint_callable = (
|
||||
authentication_download_avatar
|
||||
)
|
||||
42
Events/AllEvents/authentication/auth/cluster.py
Normal file
42
Events/AllEvents/authentication/auth/cluster.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
|
||||
from .info import authentication_page_info
|
||||
from .auth import (
|
||||
AuthenticationLoginEventMethods,
|
||||
AuthenticationLogoutEventMethods,
|
||||
AuthenticationRefreshTokenEventMethods,
|
||||
AuthenticationForgotPasswordEventMethods,
|
||||
AuthenticationChangePasswordEventMethods,
|
||||
AuthenticationCheckTokenEventMethods,
|
||||
AuthenticationCreatePasswordEventMethods,
|
||||
AuthenticationDisconnectUserEventMethods,
|
||||
AuthenticationDownloadAvatarEventMethods,
|
||||
AuthenticationResetPasswordEventMethods,
|
||||
AuthenticationRefreshEventMethods,
|
||||
AuthenticationSelectEventMethods,
|
||||
)
|
||||
|
||||
|
||||
AuthCluster = CategoryCluster(
|
||||
name="AuthCluster",
|
||||
tags=["authentication"],
|
||||
prefix="/authentication",
|
||||
description="Authentication cluster",
|
||||
pageinfo=authentication_page_info,
|
||||
endpoints={
|
||||
"AuthenticationLoginEventMethods": AuthenticationLoginEventMethods,
|
||||
"AuthenticationLogoutEventMethods": AuthenticationLogoutEventMethods,
|
||||
"AuthenticationRefreshTokenEventMethods": AuthenticationRefreshTokenEventMethods,
|
||||
"AuthenticationForgotPasswordEventMethods": AuthenticationForgotPasswordEventMethods,
|
||||
"AuthenticationChangePasswordEventMethods": AuthenticationChangePasswordEventMethods,
|
||||
"AuthenticationCheckTokenEventMethods": AuthenticationCheckTokenEventMethods,
|
||||
"AuthenticationCreatePasswordEventMethods": AuthenticationCreatePasswordEventMethods,
|
||||
"AuthenticationDisconnectUserEventMethods": AuthenticationDisconnectUserEventMethods,
|
||||
"AuthenticationDownloadAvatarEventMethods": AuthenticationDownloadAvatarEventMethods,
|
||||
"AuthenticationResetPasswordEventMethods": AuthenticationResetPasswordEventMethods,
|
||||
"AuthenticationRefreshEventMethods": AuthenticationRefreshEventMethods,
|
||||
"AuthenticationSelectEventMethods": AuthenticationSelectEventMethods,
|
||||
},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
529
Events/AllEvents/authentication/auth/function_handlers.py
Normal file
529
Events/AllEvents/authentication/auth/function_handlers.py
Normal file
@@ -0,0 +1,529 @@
|
||||
from typing import Any, Union
|
||||
from fastapi import Request
|
||||
|
||||
from ApiLayers.ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ApiLayers.ApiServices.Login.user_login_handler import UserLoginModule
|
||||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||
from ApiLayers.ApiValidations.Custom.token_objects import CompanyToken, OccupantToken
|
||||
from ApiLayers.ApiValidations.Response.default_response import (
|
||||
EndpointSuccessResponse,
|
||||
EndpointNotAcceptableResponse,
|
||||
EndpointBadRequestResponse,
|
||||
)
|
||||
from ApiLayers.ErrorHandlers import HTTPExceptionApi
|
||||
from ApiLayers.Schemas import (
|
||||
BuildLivingSpace,
|
||||
BuildParts,
|
||||
RelationshipEmployee2Build,
|
||||
Companies,
|
||||
Departments,
|
||||
Duties,
|
||||
Duty,
|
||||
Staff,
|
||||
Employees,
|
||||
Event2Employee,
|
||||
Event2Occupant,
|
||||
OccupantTypes,
|
||||
Users,
|
||||
UsersTokens,
|
||||
)
|
||||
from Events.base_request_model import TokenDictType, BaseRouteModel
|
||||
from Services.Redis.Actions.actions import RedisActions
|
||||
from ApiLayers.AllConfigs.Redis.configs import RedisAuthKeys
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_employee_selection(
|
||||
cls, request: Request, data: Any, token_dict: TokenDictType
|
||||
):
|
||||
db = Users.new_session()
|
||||
if data.company_uu_id not in token_dict.companies_uu_id_list:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Company not found in token",
|
||||
)
|
||||
selected_company: Companies = Companies.filter_one(
|
||||
Companies.uu_id == data.company_uu_id, db=db
|
||||
).data
|
||||
if not selected_company:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Company not found in token",
|
||||
)
|
||||
|
||||
# Get duties IDs for the company
|
||||
duties_ids = [
|
||||
duty.id
|
||||
for duty in Duties.filter_all(
|
||||
Duties.company_id == selected_company.id, db=db
|
||||
).data
|
||||
]
|
||||
|
||||
# Get staff IDs
|
||||
staff_ids = [
|
||||
staff.id
|
||||
for staff in Staff.filter_all(Staff.duties_id.in_(duties_ids), db=db).data
|
||||
]
|
||||
|
||||
# Get employee
|
||||
employee: Employees = Employees.filter_one(
|
||||
Employees.people_id == token_dict.person_id,
|
||||
Employees.staff_id.in_(staff_ids),
|
||||
db=db,
|
||||
).data
|
||||
|
||||
if not employee:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Employee not found in token",
|
||||
)
|
||||
|
||||
# Get reachable events
|
||||
reachable_event_codes = Event2Employee.get_event_codes(employee_id=employee.id)
|
||||
|
||||
# Get staff and duties
|
||||
staff = Staff.filter_one(Staff.id == employee.staff_id, db=db).data
|
||||
duties = Duties.filter_one(Duties.id == staff.duties_id, db=db).data
|
||||
department = Departments.filter_one(
|
||||
Departments.id == duties.department_id, db=db
|
||||
).data
|
||||
|
||||
# Get bulk duty
|
||||
bulk_id = Duty.filter_by_one(system=True, duty_code="BULK", db=db).data
|
||||
bulk_duty_id = Duties.filter_by_one(
|
||||
company_id=selected_company.id,
|
||||
duties_id=bulk_id.id,
|
||||
db=db,
|
||||
).data
|
||||
|
||||
# Create company token
|
||||
company_token = CompanyToken(
|
||||
company_uu_id=selected_company.uu_id.__str__(),
|
||||
company_id=selected_company.id,
|
||||
department_id=department.id,
|
||||
department_uu_id=department.uu_id.__str__(),
|
||||
duty_id=duties.id,
|
||||
duty_uu_id=duties.uu_id.__str__(),
|
||||
bulk_duties_id=bulk_duty_id.id,
|
||||
staff_id=staff.id,
|
||||
staff_uu_id=staff.uu_id.__str__(),
|
||||
employee_id=employee.id,
|
||||
employee_uu_id=employee.uu_id.__str__(),
|
||||
reachable_event_codes=reachable_event_codes,
|
||||
)
|
||||
|
||||
try: # Update Redis
|
||||
return TokenService.update_token_at_redis(
|
||||
request=request, add_payload=company_token
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg=f"{e}",
|
||||
)
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_occupant_selection(
|
||||
cls, request: Request, data: Any, token_dict: TokenDictType
|
||||
):
|
||||
"""Handle occupant type selection"""
|
||||
db = BuildLivingSpace.new_session()
|
||||
# Get selected occupant type
|
||||
selected_build_living_space: BuildLivingSpace = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.uu_id == data.build_living_space_uu_id,
|
||||
db=db,
|
||||
).data
|
||||
if not selected_build_living_space:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang=token_dict.lang,
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg="Selected occupant type not found",
|
||||
)
|
||||
|
||||
# Get reachable events
|
||||
reachable_event_codes = Event2Occupant.get_event_codes(
|
||||
build_living_space_id=selected_build_living_space.id
|
||||
)
|
||||
occupant_type = OccupantTypes.filter_one_system(
|
||||
OccupantTypes.id == selected_build_living_space.occupant_type_id,
|
||||
db=db,
|
||||
).data
|
||||
build_part = BuildParts.filter_one(
|
||||
BuildParts.id == selected_build_living_space.build_parts_id,
|
||||
db=db,
|
||||
).data
|
||||
build = BuildParts.filter_one(
|
||||
BuildParts.id == build_part.build_id,
|
||||
db=db,
|
||||
).data
|
||||
responsible_employee = Employees.filter_one(
|
||||
Employees.id == build_part.responsible_employee_id,
|
||||
db=db,
|
||||
).data
|
||||
related_company = RelationshipEmployee2Build.filter_one(
|
||||
RelationshipEmployee2Build.member_id == build.id,
|
||||
db=db,
|
||||
).data
|
||||
# Get company
|
||||
company_related = Companies.filter_one(
|
||||
Companies.id == related_company.company_id,
|
||||
db=db,
|
||||
).data
|
||||
|
||||
# Create occupant token
|
||||
occupant_token = OccupantToken(
|
||||
living_space_id=selected_build_living_space.id,
|
||||
living_space_uu_id=selected_build_living_space.uu_id.__str__(),
|
||||
occupant_type_id=occupant_type.id,
|
||||
occupant_type_uu_id=occupant_type.uu_id.__str__(),
|
||||
occupant_type=occupant_type.occupant_type,
|
||||
build_id=build.id,
|
||||
build_uuid=build.uu_id.__str__(),
|
||||
build_part_id=build_part.id,
|
||||
build_part_uuid=build_part.uu_id.__str__(),
|
||||
responsible_employee_id=responsible_employee.id,
|
||||
responsible_employee_uuid=responsible_employee.uu_id.__str__(),
|
||||
responsible_company_id=company_related.id,
|
||||
responsible_company_uuid=company_related.uu_id.__str__(),
|
||||
reachable_event_codes=reachable_event_codes,
|
||||
)
|
||||
|
||||
try: # Update Redis
|
||||
return TokenService.update_token_at_redis(
|
||||
request=request, add_payload=occupant_token
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
sys_msg=f"{e}",
|
||||
)
|
||||
|
||||
|
||||
class AuthenticationFunctions(BaseRouteModel):
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def authentication_login_with_domain_and_creds(cls, request: Request, data: Any):
|
||||
"""
|
||||
Authenticate user with domain and credentials.
|
||||
|
||||
Args:
|
||||
request: FastAPI request object
|
||||
data: Request body containing login credentials
|
||||
{
|
||||
"data": {
|
||||
"domain": "evyos.com.tr",
|
||||
"access_key": "karatay.berkay.sup@evyos.com.tr",
|
||||
"password": "string",
|
||||
"remember_me": false
|
||||
}
|
||||
}
|
||||
Returns:
|
||||
SuccessResponse containing authentication token and user info
|
||||
"""
|
||||
|
||||
# Get token from login module
|
||||
user_login_module = UserLoginModule(request=request)
|
||||
user_login_module.login_user_via_credentials(access_data=data)
|
||||
user_login_module.language = "en"
|
||||
|
||||
# Return response with token and headers
|
||||
return EndpointSuccessResponse(
|
||||
code="LOGIN_SUCCESS", lang=user_login_module.language
|
||||
).as_dict(data=user_login_module.as_dict)
|
||||
|
||||
@classmethod # Requires auth context
|
||||
def authentication_select_company_or_occupant_type(cls, data: Any):
|
||||
"""
|
||||
Handle selection of company or occupant type
|
||||
{"data": {"build_living_space_uu_id": ""}} | {"data": {"company_uu_id": ""}}
|
||||
{
|
||||
"data": {"company_uu_id": "e9869a25-ba4d-49dc-bb0d-8286343b184b"}
|
||||
}
|
||||
|
||||
{
|
||||
"data": {"build_living_space_uu_id": "e9869a25-ba4d-49dc-bb0d-8286343b184b"}
|
||||
}
|
||||
"""
|
||||
selection_dict = dict(
|
||||
request=cls.context_retriever.request,
|
||||
token_dict=cls.context_retriever.token,
|
||||
data=data,
|
||||
)
|
||||
if cls.context_retriever.token.is_employee:
|
||||
if Handlers.handle_employee_selection(**selection_dict):
|
||||
return EndpointSuccessResponse(
|
||||
code="LOGIN_SELECT", lang=cls.context_retriever.token.lang
|
||||
).as_dict(
|
||||
data={"selected": data.company_uu_id, **cls.context_retriever.base}
|
||||
)
|
||||
elif cls.context_retriever.token.is_occupant:
|
||||
if Handlers.handle_occupant_selection(**selection_dict):
|
||||
return EndpointSuccessResponse(
|
||||
code="LOGIN_SELECT", lang=cls.context_retriever.token.lang
|
||||
).as_dict(
|
||||
data={
|
||||
"selected": data.build_living_space_uu_id,
|
||||
**cls.context_retriever.base,
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod # Requires auth context
|
||||
def authentication_check_token_is_valid(cls):
|
||||
"""Check if token is valid for user"""
|
||||
if cls.context_retriever.token:
|
||||
return EndpointSuccessResponse(
|
||||
code="TOKEN_VALID", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data=cls.context_retriever.base)
|
||||
return {
|
||||
"completed": False,
|
||||
"message": "Token is not valid",
|
||||
}
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_access_token_user_info(cls):
|
||||
"""Refresh user info using access token"""
|
||||
if cls.context_retriever.token:
|
||||
db = Users.new_session()
|
||||
if found_user := Users.filter_one(
|
||||
Users.id == cls.context_retriever.token.user_id, db=db
|
||||
).data:
|
||||
return EndpointSuccessResponse(
|
||||
code="USER_INFO_REFRESHED", lang=cls.context_retriever.token.lang
|
||||
).as_dict(
|
||||
{
|
||||
"access_token": cls.context_retriever.get_token,
|
||||
"user": found_user.get_dict(),
|
||||
}
|
||||
)
|
||||
if not found_user:
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="USER_NOT_FOUND", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={})
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def authentication_change_password(cls, data: Any):
|
||||
"""Change password with access token"""
|
||||
if cls.context_retriever.token:
|
||||
db = Users.new_session()
|
||||
if found_user := Users.filter_one(
|
||||
Users.id == cls.context_retriever.token.user_id, db=db
|
||||
).data:
|
||||
found_user.set_password(data.new_password)
|
||||
return EndpointSuccessResponse(
|
||||
code="PASSWORD_CHANGED", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={"user": found_user.get_dict()})
|
||||
if not found_user:
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="USER_NOT_FOUND", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={})
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_create_password(cls, data: Any):
|
||||
"""Create password with password reset token requested via email"""
|
||||
db = Users.new_session()
|
||||
if not data.re_password == data.password:
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="PASSWORD_NOT_MATCH", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={"password": data.password, "re_password": data.re_password})
|
||||
if found_user := Users.filter_one(
|
||||
Users.password_token == data.password_token, db=db
|
||||
).data:
|
||||
found_user.create_password(found_user=found_user, password=data.password)
|
||||
found_user.password_token = ""
|
||||
found_user.save()
|
||||
return EndpointSuccessResponse(
|
||||
code="CREATED_PASSWORD", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={"user": found_user.get_dict()})
|
||||
|
||||
@classmethod # Requires auth context
|
||||
def authentication_disconnect_user(cls):
|
||||
"""Disconnect all sessions of user in access token"""
|
||||
db = Users.new_session()
|
||||
found_user = Users.filter_one_system(
|
||||
Users.id == cls.context_retriever.token.user_id, db=db
|
||||
).data
|
||||
if not found_user:
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="USER_NOT_FOUND", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={})
|
||||
registered_tokens = UsersTokens.filter_all(
|
||||
UsersTokens.user_id == cls.context_retriever.token.user_id, db=db
|
||||
)
|
||||
if registered_tokens.count:
|
||||
registered_tokens.query.delete()
|
||||
UsersTokens.save(db=db)
|
||||
|
||||
RedisActions.delete(
|
||||
list_keys=[f"{RedisAuthKeys.AUTH}:*:{str(found_user.uu_id)}"]
|
||||
)
|
||||
return EndpointSuccessResponse(
|
||||
code="DISCONNECTED_USER", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={"user": found_user.get_dict()})
|
||||
|
||||
@classmethod # Requires auth context
|
||||
def authentication_logout_user(cls, data: Any):
|
||||
"""Logout only single session of user which domain is provided"""
|
||||
db = Users.new_session()
|
||||
found_user = Users.filter_one_system(
|
||||
Users.id == cls.context_retriever.token.user_id, db=db
|
||||
).data
|
||||
if not found_user:
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="USER_NOT_FOUND", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={})
|
||||
registered_tokens = UsersTokens.filter_all_system(
|
||||
UsersTokens.user_id == cls.context_retriever.token.user_id,
|
||||
UsersTokens.domain == cls.context_retriever.token.domain,
|
||||
db=db,
|
||||
)
|
||||
if registered_tokens.count:
|
||||
registered_tokens.query.delete()
|
||||
UsersTokens.save(db=db)
|
||||
TokenService.remove_token_with_domain(user=found_user, domain=data.domain)
|
||||
return EndpointSuccessResponse(
|
||||
code="LOGOUT_USER", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={"user": found_user.get_dict()})
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_refresher_token(cls, request: Request, data: Any):
|
||||
"""
|
||||
Refresh access token with refresher token
|
||||
{
|
||||
"data": {
|
||||
"refresh_token": "string",
|
||||
"domain": "string"
|
||||
}
|
||||
}
|
||||
"""
|
||||
import arrow
|
||||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||
|
||||
db = UsersTokens.new_session()
|
||||
token_refresher: UsersTokens = UsersTokens.filter_by_one(
|
||||
token=data.refresh_token,
|
||||
domain=data.domain,
|
||||
db=db,
|
||||
).data
|
||||
language = request.headers.get("evyos-language", "tr")
|
||||
if not token_refresher:
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="REFRESHER_NOT_FOUND", lang=language
|
||||
).as_dict(data={"refresh_token": data.refresh_token})
|
||||
|
||||
if found_user := Users.filter_one(
|
||||
Users.id == token_refresher.user_id, db=db
|
||||
).data:
|
||||
token_created = TokenService.set_access_token_to_redis(
|
||||
request=request,
|
||||
user=found_user,
|
||||
domain=data.domain,
|
||||
remember=True,
|
||||
)
|
||||
found_user.last_agent = request.headers.get("User-Agent", None)
|
||||
found_user.last_platform = request.headers.get("Origin", None)
|
||||
found_user.last_remote_addr = getattr(
|
||||
request, "remote_addr", None
|
||||
) or request.headers.get("X-Forwarded-For", None)
|
||||
found_user.last_seen = str(arrow.now())
|
||||
response_data = {
|
||||
"access_token": token_created.get("access_token"),
|
||||
"refresh_token": data.refresh_token,
|
||||
}
|
||||
return EndpointSuccessResponse(code="TOKEN_REFRESH", lang=language).as_dict(
|
||||
data=response_data
|
||||
)
|
||||
raise EndpointNotAcceptableResponse(
|
||||
code="USER_NOT_FOUND", lang=language
|
||||
).as_dict(data={})
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_forgot_password(cls, data: Any):
|
||||
"""Send an email to user for a valid password reset token"""
|
||||
import arrow
|
||||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||
from ApiLayers.AllConfigs.Templates.password_templates import (
|
||||
change_your_password_template,
|
||||
)
|
||||
from Services.Email.send_email import email_sender
|
||||
|
||||
from config import ApiStatic
|
||||
|
||||
db = Users.new_session()
|
||||
request = cls.context_retriever.request
|
||||
found_user: Users = Users.check_user_exits(
|
||||
access_key=data.access_key, domain=data.domain
|
||||
)
|
||||
forgot_key = TokenService._create_access_token(access=False)
|
||||
forgot_link = ApiStatic.forgot_link(forgot_key=forgot_key)
|
||||
send_email_completed = email_sender.send_email(
|
||||
subject=f"Dear {found_user.user_tag}, your forgot password link has been sent.",
|
||||
receivers=[str(found_user.email)],
|
||||
html=change_your_password_template(
|
||||
user_name=found_user.user_tag, forgot_link=forgot_link
|
||||
),
|
||||
)
|
||||
if not send_email_completed:
|
||||
return EndpointBadRequestResponse(
|
||||
code="EMAIL_NOT_SENT", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={"email": found_user.email})
|
||||
found_user.password_token = forgot_key
|
||||
found_user.password_token_is_valid = str(arrow.now().shift(days=1))
|
||||
found_user.save(db=db)
|
||||
return EndpointSuccessResponse(
|
||||
code="FORGOT_PASSWORD", lang=cls.context_retriever.token.lang
|
||||
).as_dict(
|
||||
data={
|
||||
"user": found_user.get_dict(),
|
||||
"forgot_link": forgot_link,
|
||||
"token": forgot_key,
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_reset_password(cls, data: Any):
|
||||
"""Reset password with forgot password token"""
|
||||
return cls.context_retriever.base
|
||||
|
||||
@classmethod # Requires not auth context
|
||||
def authentication_download_avatar(cls):
|
||||
"""Download avatar icon and profile info of user"""
|
||||
import arrow
|
||||
|
||||
db = Users.new_session()
|
||||
if found_user := Users.filter_one(
|
||||
Users.id == cls.context_retriever.token.user_id, db=db
|
||||
).data:
|
||||
expired_starts = str(arrow.now() - arrow.get(str(found_user.expiry_ends)))
|
||||
expired_int = (
|
||||
arrow.now().datetime - arrow.get(str(found_user.expiry_ends)).datetime
|
||||
)
|
||||
user_info = {
|
||||
"lang": cls.context_retriever.token.lang,
|
||||
"full_name": found_user.person.full_name,
|
||||
"avatar": found_user.avatar,
|
||||
"remember_me": found_user.remember_me,
|
||||
"expiry_ends": str(found_user.expiry_ends),
|
||||
"expired_humanized": expired_starts,
|
||||
"expired_day": int(expired_int.days) * -1,
|
||||
}
|
||||
return EndpointSuccessResponse(
|
||||
code="USER_AVATAR", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data=user_info)
|
||||
return EndpointNotAcceptableResponse(
|
||||
code="USER_NOT_FOUND", lang=cls.context_retriever.token.lang
|
||||
).as_dict(data={})
|
||||
11
Events/AllEvents/authentication/auth/info.py
Normal file
11
Events/AllEvents/authentication/auth/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
authentication_page_info = PageInfo(
|
||||
name="Authentication",
|
||||
url="",
|
||||
language_models={},
|
||||
endpoints={},
|
||||
icon="Authentication",
|
||||
sub_components=[],
|
||||
)
|
||||
24
Events/AllEvents/authentication/auth/models.py
Normal file
24
Events/AllEvents/authentication/auth/models.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from ApiLayers.ApiValidations.Request import (
|
||||
Login,
|
||||
EmployeeSelection,
|
||||
OccupantSelection,
|
||||
Logout,
|
||||
CreatePassword,
|
||||
ChangePassword,
|
||||
Forgot,
|
||||
Remember,
|
||||
)
|
||||
|
||||
|
||||
class AuthenticationRequestModels:
|
||||
LoginSuperUserRequestModel = Login
|
||||
SelectCompanyOrOccupantTypeSuperUserRequestModel = {
|
||||
"EmployeeSelection": EmployeeSelection,
|
||||
"OccupantSelection": OccupantSelection,
|
||||
}
|
||||
RefresherRequestModel = Remember
|
||||
LogoutRequestModel = Logout
|
||||
|
||||
|
||||
class AuthenticationResponseModels:
|
||||
pass
|
||||
9
Events/AllEvents/events/__init__.py
Normal file
9
Events/AllEvents/events/__init__.py
Normal file
@@ -0,0 +1,9 @@
|
||||
"""
|
||||
Events package initialization.
|
||||
"""
|
||||
|
||||
from .account.cluster import AccountCluster
|
||||
from .address.cluster import AddressCluster
|
||||
|
||||
|
||||
__all__ = ["AccountCluster", "AddressCluster"]
|
||||
124
Events/AllEvents/events/account/account_records.py
Normal file
124
Events/AllEvents/events/account/account_records.py
Normal file
@@ -0,0 +1,124 @@
|
||||
"""
|
||||
Account related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
from fastapi import Request
|
||||
|
||||
from Events.Engine.abstract_class import MethodToEvent
|
||||
from Events.base_request_model import EndpointBaseRequestModel, ContextRetrievers
|
||||
from ApiLayers.Middleware.token_event_middleware import TokenEventMiddleware
|
||||
from ApiLayers.ApiValidations.Response.default_response import (
|
||||
EndpointSuccessListResponse,
|
||||
)
|
||||
|
||||
from .function_handlers import AccountListEventMethods
|
||||
from .api_events import SuperUserAccountEvents
|
||||
|
||||
|
||||
AccountRecordsListEventMethods = MethodToEvent(
|
||||
name="AccountRecordsListEventMethods",
|
||||
events={
|
||||
SuperUserAccountEvents.SuperUserListEvent.key: SuperUserAccountEvents.SuperUserListEvent,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/list",
|
||||
method="POST",
|
||||
summary="List all accounts by given previligous",
|
||||
description="List all accounts by given previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_list_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_list_event_endpoint)
|
||||
event_2_catch = AccountRecordsListEventMethods.retrieve_event(
|
||||
event_function_code=f"{SuperUserAccountEvents.SuperUserListEvent.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AccountListEventMethods.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AccountRecordsListEventMethods.endpoint_callable = account_list_event_endpoint
|
||||
|
||||
|
||||
AccountRecordsCreateEventMethods = MethodToEvent(
|
||||
name="AccountRecordsCreateEventMethods",
|
||||
events={
|
||||
SuperUserAccountEvents.SuperUserCreateEvent.key: SuperUserAccountEvents.SuperUserCreateEvent,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/create",
|
||||
method="POST",
|
||||
summary="Create Account via given data and previligous",
|
||||
description="Create Account via given data and previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_create_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_create_event_endpoint)
|
||||
event_2_catch = AccountRecordsCreateEventMethods.retrieve_event(
|
||||
event_function_code=f"{SuperUserAccountEvents.SuperUserCreateEvent.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AccountListEventMethods.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AccountRecordsCreateEventMethods.endpoint_callable = account_create_event_endpoint
|
||||
|
||||
|
||||
AccountRecordsUpdateEventMethods = MethodToEvent(
|
||||
name="AccountRecordsUpdateEventMethods",
|
||||
events={
|
||||
SuperUserAccountEvents.SuperUserUpdateEvent.key: SuperUserAccountEvents.SuperUserUpdateEvent,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/update",
|
||||
method="POST",
|
||||
summary="Update Account via given data and previligous",
|
||||
description="Update Account via given data and previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_update_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_update_event_endpoint)
|
||||
event_2_catch = AccountRecordsUpdateEventMethods.retrieve_event(
|
||||
event_function_code=f"{SuperUserAccountEvents.SuperUserUpdateEvent.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AccountListEventMethods.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AccountRecordsUpdateEventMethods.endpoint_callable = account_update_event_endpoint
|
||||
77
Events/AllEvents/events/account/api_events.py
Normal file
77
Events/AllEvents/events/account/api_events.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
|
||||
from .models import AccountRequestValidators
|
||||
from .function_handlers import (
|
||||
AccountListEventMethods,
|
||||
AccountCreateEventMethods,
|
||||
AccountUpdateEventMethods,
|
||||
)
|
||||
|
||||
|
||||
# class SelectResponseAccount(BaseModel):
|
||||
# """
|
||||
# Response model for account list.
|
||||
# """
|
||||
# neighborhood_code: str
|
||||
# neighborhood_name: str
|
||||
# type_code: str
|
||||
# type_description: str
|
||||
#
|
||||
|
||||
|
||||
# Auth Login
|
||||
account_list_super_user_event = Event(
|
||||
name="account_list_super_user_event",
|
||||
key="7192c2aa-5352-4e36-98b3-dafb7d036a3d",
|
||||
request_validator=AccountRequestValidators.ListAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="ACCOUNTS_LIST",
|
||||
description="List all types of accounts by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
account_list_super_user_event.endpoint_callable = (
|
||||
AccountListEventMethods.account_records_list
|
||||
)
|
||||
|
||||
|
||||
account_insert_super_user_event = Event(
|
||||
name="account_insert_super_user_event",
|
||||
key="31f4f32f-0cd4-4995-8a6a-f9f56335848a",
|
||||
request_validator=AccountRequestValidators.InsertAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="ACCOUNT_CREATED",
|
||||
description="Create a new account by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
account_insert_super_user_event.endpoint_callable = (
|
||||
AccountCreateEventMethods.account_records_create
|
||||
)
|
||||
|
||||
|
||||
account_update_super_user_event = Event(
|
||||
name="account_insert_super_user_event",
|
||||
key="208e6273-17ef-44f0-814a-8098f816b63a",
|
||||
request_validator=AccountRequestValidators.UpdateAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="ACCOUNT_UPDATED",
|
||||
description="Update a specific account by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
account_update_super_user_event.endpoint_callable = (
|
||||
AccountUpdateEventMethods.account_records_update
|
||||
)
|
||||
|
||||
|
||||
class SuperUserAccountEvents:
|
||||
SuperUserListEvent = account_list_super_user_event
|
||||
SuperUserCreateEvent = account_insert_super_user_event
|
||||
SuperUserUpdateEvent = account_update_super_user_event
|
||||
38
Events/AllEvents/events/account/bases.py
Normal file
38
Events/AllEvents/events/account/bases.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from Events.Engine.abstract_class import DefaultClusterName
|
||||
|
||||
|
||||
cluster_name = "AccountCluster"
|
||||
prefix = "/accounts"
|
||||
icon = "Building"
|
||||
|
||||
|
||||
# Keys for the cluster
|
||||
class KeyValidations:
|
||||
headers = "headers"
|
||||
data = "data"
|
||||
validation = "validations"
|
||||
|
||||
# Key URLS for the cluster
|
||||
class KeyURLs:
|
||||
validations = "/validations/validations"
|
||||
|
||||
# Keys for the cluster
|
||||
class KeyBases:
|
||||
create_key = f"{prefix}/create"
|
||||
update_key = f"{prefix}/update"
|
||||
list_key = f"{prefix}/list"
|
||||
|
||||
|
||||
# Page Variations of the cluster
|
||||
class PageBases:
|
||||
CREATE = f"/create?{DefaultClusterName}={cluster_name}"
|
||||
UPDATE = f"/update?{DefaultClusterName}={cluster_name}"
|
||||
DASHBOARD = f"/dashboard?{DefaultClusterName}={cluster_name}"
|
||||
|
||||
|
||||
# Match the keys with the pages
|
||||
page_2_keys = {
|
||||
KeyBases.create_key: PageBases.CREATE,
|
||||
KeyBases.update_key: PageBases.UPDATE,
|
||||
KeyBases.list_key: PageBases.DASHBOARD,
|
||||
}
|
||||
26
Events/AllEvents/events/account/cluster.py
Normal file
26
Events/AllEvents/events/account/cluster.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from .account_records import (
|
||||
AccountRecordsListEventMethods,
|
||||
AccountRecordsCreateEventMethods,
|
||||
AccountRecordsUpdateEventMethods,
|
||||
)
|
||||
from .bases import cluster_name, prefix, page_2_keys
|
||||
from .info import page_infos
|
||||
|
||||
|
||||
AccountCluster = CategoryCluster(
|
||||
name=cluster_name,
|
||||
tags=["Account Records"],
|
||||
prefix=prefix,
|
||||
description="Account Cluster Actions",
|
||||
pageinfo=page_infos,
|
||||
endpoints={
|
||||
"AccountRecordsCreateEventMethods": AccountRecordsCreateEventMethods,
|
||||
"AccountRecordsUpdateEventMethods": AccountRecordsUpdateEventMethods,
|
||||
"AccountRecordsListEventMethods": AccountRecordsListEventMethods,
|
||||
},
|
||||
mapping=page_2_keys,
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
is_client=True,
|
||||
)
|
||||
305
Events/AllEvents/events/account/function_handlers.py
Normal file
305
Events/AllEvents/events/account/function_handlers.py
Normal file
@@ -0,0 +1,305 @@
|
||||
"""
|
||||
Account records service implementation.
|
||||
"""
|
||||
|
||||
from typing import Any, Union, Optional
|
||||
|
||||
from ApiLayers.ApiLibrary import system_arrow
|
||||
from ApiLayers.ApiValidations.Custom.token_objects import (
|
||||
OccupantTokenObject,
|
||||
EmployeeTokenObject,
|
||||
)
|
||||
from ApiLayers.ApiValidations.Request import (
|
||||
InsertAccountRecord,
|
||||
UpdateAccountRecord,
|
||||
ListOptions,
|
||||
)
|
||||
from ApiLayers.Schemas import (
|
||||
BuildLivingSpace,
|
||||
BuildDecisionBookPayments,
|
||||
AccountRecords,
|
||||
BuildIbans,
|
||||
ApiEnumDropdown,
|
||||
)
|
||||
from ApiLayers.ApiValidations.Response import AccountRecordResponse
|
||||
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class AccountListEventMethods(BaseRouteModel):
|
||||
"""
|
||||
Account records list by with full privileges.
|
||||
Accepts List Options
|
||||
{
|
||||
"data": {
|
||||
"page": 1,
|
||||
"size": 10,
|
||||
"order_field": ["uu_id",]
|
||||
"order_type": ["desc"],
|
||||
"query": {
|
||||
"process_date__gt": "2021-09-01",
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def account_records_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AccountRecords,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AccountRecords.pre_query = AccountRecords.filter_all(
|
||||
AccountRecords.company_id
|
||||
== cls.context_retriever.token.selected_occupant.responsible_company_id,
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AccountRecords.pre_query = AccountRecords.filter_all(
|
||||
AccountRecords.company_id
|
||||
== cls.context_retriever.token.selected_company.company_id,
|
||||
db=db_session,
|
||||
).query
|
||||
records = AccountRecords.filter_all(*query_options.convert(), db=db_session)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
|
||||
|
||||
class AccountCreateEventMethods(BaseRouteModel):
|
||||
|
||||
@classmethod
|
||||
def account_records_create(cls, data: Any):
|
||||
data_dict = data.excluded_dump()
|
||||
db_session = AccountRecords.new_session()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
build_iban = BuildIbans.filter_one(
|
||||
BuildIbans.iban == data.iban,
|
||||
BuildIbans.build_id
|
||||
== cls.context_retriever.token.selected_occupant.build_id,
|
||||
db=db_session,
|
||||
).data
|
||||
if not build_iban:
|
||||
raise BuildIbans.raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="UNAUTHORIZED",
|
||||
message=f"{data.iban} is not found in company related to your organization",
|
||||
data={"iban": data.iban},
|
||||
)
|
||||
account_record = AccountRecords.find_or_create(**data.excluded_dump())
|
||||
# return AlchemyJsonResponse(
|
||||
# completed=True,
|
||||
# message="Account record created successfully",
|
||||
# result=account_record,
|
||||
# )
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
# Build.pre_query = Build.select_action(
|
||||
# employee_id=token_dict.selected_employee.employee_id,
|
||||
# )
|
||||
# build_ids_list = Build.filter_all(
|
||||
# )
|
||||
# build_iban = BuildIbans.filter_one(
|
||||
# BuildIbans.iban == data.iban,
|
||||
# BuildIbans.build_id.in_([build.id for build in build_ids_list.data]),
|
||||
# ).data
|
||||
# if not build_iban:
|
||||
# BuildIbans.raise_http_exception(
|
||||
# status_code="HTTP_404_NOT_FOUND",
|
||||
# error_case="UNAUTHORIZED",
|
||||
# message=f"{data.iban} is not found in company related to your organization",
|
||||
# data={
|
||||
# "iban": data.iban,
|
||||
# },
|
||||
# )
|
||||
bank_date = system_arrow.get(data.bank_date)
|
||||
data_dict["bank_date_w"] = bank_date.weekday()
|
||||
data_dict["bank_date_m"] = bank_date.month
|
||||
data_dict["bank_date_d"] = bank_date.day
|
||||
data_dict["bank_date_y"] = bank_date.year
|
||||
|
||||
if int(data.currency_value) < 0:
|
||||
debit_type = ApiEnumDropdown.filter_by_one(
|
||||
system=True, enum_class="DebitTypes", key="DT-D", db=db_session
|
||||
).data
|
||||
data_dict["receive_debit"] = debit_type.id
|
||||
data_dict["receive_debit_uu_id"] = str(debit_type.uu_id)
|
||||
else:
|
||||
debit_type = ApiEnumDropdown.filter_by_one(
|
||||
system=True, enum_class="DebitTypes", key="DT-R", db=db_session
|
||||
).data
|
||||
data_dict["receive_debit"] = debit_type.id
|
||||
data_dict["receive_debit_uu_id"] = str(debit_type.uu_id)
|
||||
|
||||
account_record = AccountRecords.find_or_create(
|
||||
data_dict, db=db_session
|
||||
).data
|
||||
# return AlchemyJsonResponse(
|
||||
# completed=True,
|
||||
# message="Account record created successfully",
|
||||
# result=account_record,
|
||||
# )
|
||||
|
||||
|
||||
class AccountUpdateEventMethods(BaseRouteModel):
|
||||
|
||||
@classmethod
|
||||
def account_records_update(cls, build_uu_id: str, data: Any):
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
pass
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
pass
|
||||
AccountRecords.build_parts_id = (
|
||||
cls.context_retriever.token.selected_occupant.build_part_id
|
||||
)
|
||||
|
||||
# return AlchemyJsonResponse(
|
||||
# completed=True,
|
||||
# message="Account record updated successfully",
|
||||
# result=account_record,
|
||||
# cls_object=AccountRecords,
|
||||
# response_model=UpdateAccountRecord,
|
||||
# )
|
||||
|
||||
|
||||
# @classmethod
|
||||
# def account_records_list_flt_res(cls, list_options: ListOptions) -> PaginationResult:
|
||||
# list_options_base = ListOptionsBase(
|
||||
# table=AccountRecords, list_options=list_options, model_query=None,
|
||||
# )
|
||||
# db_session, query_options = list_options_base.init_list_options()
|
||||
# if not cls.context_retriever.token.is_occupant:
|
||||
# raise AccountRecords.raise_http_exception(
|
||||
# status_code="HTTP_404_NOT_FOUND",
|
||||
# error_case="UNAUTHORIZED",
|
||||
# message="Only Occupant can see this data",
|
||||
# data={},
|
||||
# )
|
||||
#
|
||||
# return_list = []
|
||||
# living_space: BuildLivingSpace = BuildLivingSpace.filter_by_one(
|
||||
# id=cls.context_retriever.token.selected_occupant.living_space_id, db=db_session
|
||||
# ).data
|
||||
# if not living_space:
|
||||
# raise AccountRecords.raise_http_exception(
|
||||
# status_code="HTTP_404_NOT_FOUND",
|
||||
# error_case="UNAUTHORIZED",
|
||||
# message="Living space not found",
|
||||
# data={},
|
||||
# )
|
||||
#
|
||||
# if not list_options:
|
||||
# list_options = ListOptions()
|
||||
#
|
||||
# main_filters = [
|
||||
# AccountRecords.living_space_id
|
||||
# == cls.context_retriever.token.selected_occupant.living_space_id,
|
||||
# BuildDecisionBookPayments.process_date
|
||||
# >= str(system_arrow.now().shift(months=-3).date()),
|
||||
# BuildDecisionBookPayments.process_date
|
||||
# < str(system_arrow.find_last_day_of_month(living_space.expiry_ends)),
|
||||
# BuildDecisionBookPayments.process_date
|
||||
# >= str(system_arrow.get(living_space.expiry_starts)),
|
||||
# BuildDecisionBookPayments.is_confirmed == True,
|
||||
# AccountRecords.active == True,
|
||||
# ]
|
||||
# order_type = "desc"
|
||||
# if list_options.order_type:
|
||||
# order_type = "asc" if list_options.order_type[0] == "a" else "desc"
|
||||
#
|
||||
# order_by_list = BuildDecisionBookPayments.process_date.desc()
|
||||
# if list_options.order_field:
|
||||
# if list_options.order_field == "process_date":
|
||||
# order_by_list = (
|
||||
# BuildDecisionBookPayments.process_date.asc()
|
||||
# if order_type == "asc"
|
||||
# else BuildDecisionBookPayments.process_date.desc()
|
||||
# )
|
||||
# if list_options.order_field == "bank_date":
|
||||
# order_by_list = (
|
||||
# AccountRecords.bank_date.desc()
|
||||
# if order_type == "asc"
|
||||
# else AccountRecords.bank_date.asc()
|
||||
# )
|
||||
# if list_options.order_field == "currency_value":
|
||||
# order_by_list = (
|
||||
# AccountRecords.currency_value.desc()
|
||||
# if order_type == "asc"
|
||||
# else AccountRecords.currency_value.asc()
|
||||
# )
|
||||
# if list_options.order_field == "process_comment":
|
||||
# order_by_list = (
|
||||
# AccountRecords.process_comment.desc()
|
||||
# if order_type == "asc"
|
||||
# else AccountRecords.process_comment.asc()
|
||||
# )
|
||||
# if list_options.order_field == "payment_amount":
|
||||
# order_by_list = (
|
||||
# BuildDecisionBookPayments.payment_amount.desc()
|
||||
# if order_type == "asc"
|
||||
# else BuildDecisionBookPayments.payment_amount.asc()
|
||||
# )
|
||||
#
|
||||
# if list_options.query:
|
||||
# for key, value in list_options.query.items():
|
||||
# if key == "process_date":
|
||||
# main_filters.append(BuildDecisionBookPayments.process_date == value)
|
||||
# if key == "bank_date":
|
||||
# main_filters.append(AccountRecords.bank_date == value)
|
||||
# if key == "currency":
|
||||
# main_filters.append(BuildDecisionBookPayments.currency == value)
|
||||
# if key == "currency_value":
|
||||
# main_filters.append(AccountRecords.currency_value == value)
|
||||
# if key == "process_comment":
|
||||
# main_filters.append(AccountRecords.process_comment == value)
|
||||
# if key == "payment_amount":
|
||||
# main_filters.append(
|
||||
# BuildDecisionBookPayments.payment_amount == value
|
||||
# )
|
||||
#
|
||||
# query = (
|
||||
# AccountRecords.session.query(
|
||||
# BuildDecisionBookPayments.process_date,
|
||||
# BuildDecisionBookPayments.payment_amount,
|
||||
# BuildDecisionBookPayments.currency,
|
||||
# AccountRecords.bank_date,
|
||||
# AccountRecords.currency_value,
|
||||
# AccountRecords.process_comment,
|
||||
# BuildDecisionBookPayments.uu_id,
|
||||
# )
|
||||
# .join(
|
||||
# AccountRecords,
|
||||
# AccountRecords.id == BuildDecisionBookPayments.account_records_id,
|
||||
# )
|
||||
# .filter(*main_filters)
|
||||
# ).order_by(order_by_list)
|
||||
#
|
||||
# query.limit(list_options.size or 5).offset(
|
||||
# (list_options.page or 1 - 1) * list_options.size or 5
|
||||
# )
|
||||
# for list_of_values in query.all() or []:
|
||||
# return_list.append(
|
||||
# {
|
||||
# "process_date": list_of_values[0],
|
||||
# "payment_amount": list_of_values[1],
|
||||
# "currency": list_of_values[2],
|
||||
# "bank_date": list_of_values[3],
|
||||
# "currency_value": list_of_values[4],
|
||||
# "process_comment": list_of_values[5],
|
||||
# }
|
||||
# )
|
||||
# return AlchemyJsonResponse(
|
||||
# completed=True,
|
||||
# message="Account records listed successfully",
|
||||
# result=return_list,
|
||||
# cls_object=AccountRecords,
|
||||
# filter_attributes=list_options,
|
||||
# response_model=AccountRecordResponse,
|
||||
# )
|
||||
|
||||
140
Events/AllEvents/events/account/info.py
Normal file
140
Events/AllEvents/events/account/info.py
Normal file
@@ -0,0 +1,140 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
from .bases import KeyValidations, cluster_name, KeyBases, PageBases, icon, KeyURLs
|
||||
from .account_records import (
|
||||
AccountRecordsUpdateEventMethods,
|
||||
AccountRecordsCreateEventMethods,
|
||||
AccountRecordsListEventMethods,
|
||||
)
|
||||
from .lang_models import (
|
||||
account_language_create_models_as_dict,
|
||||
account_language_model_as_dict,
|
||||
account_language_list_models_as_dict,
|
||||
account_language_created_models_as_dict,
|
||||
account_language_update_form_models_as_dict,
|
||||
)
|
||||
|
||||
|
||||
class ClustersPageInfo:
|
||||
|
||||
# Cluster Page Infos that are available for the client
|
||||
dashboard_page_info = PageInfo(
|
||||
name=f"{cluster_name}",
|
||||
url=PageBases.DASHBOARD,
|
||||
icon=icon,
|
||||
page_info={
|
||||
"en": {
|
||||
"page": "Account Records for reaching user all types account information",
|
||||
},
|
||||
"tr": {
|
||||
"page": "Kullanıcı tüm hesap bilgilerine ulaşmak için Hesap Kayıtları",
|
||||
},
|
||||
},
|
||||
instructions={
|
||||
str(KeyBases.list_key): {
|
||||
"headers": {
|
||||
"store": True,
|
||||
"url": KeyURLs.validations,
|
||||
"data": {"event_code": f"{KeyBases.list_key}", "asked_field": KeyValidations.headers},
|
||||
},
|
||||
"data": {
|
||||
"store": True,
|
||||
"url": f"{KeyBases.list_key}",
|
||||
"data": dict(page=1, limit=1),
|
||||
},
|
||||
},
|
||||
},
|
||||
endpoints={
|
||||
str(KeyBases.update_key): AccountRecordsUpdateEventMethods.retrieve_all_event_keys(),
|
||||
str(KeyBases.create_key): AccountRecordsCreateEventMethods.retrieve_all_event_keys(),
|
||||
str(KeyBases.list_key): AccountRecordsListEventMethods.retrieve_all_event_keys(),
|
||||
},
|
||||
language_models={
|
||||
str(KeyBases.list_key): {
|
||||
str(KeyBases.update_key): account_language_model_as_dict,
|
||||
str(KeyBases.create_key): account_language_created_models_as_dict,
|
||||
str(KeyBases.list_key): account_language_list_models_as_dict,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
create_page_info = PageInfo(
|
||||
name=f"{cluster_name}",
|
||||
url=PageBases.CREATE,
|
||||
icon=icon,
|
||||
instructions={
|
||||
str(KeyBases.create_key): {
|
||||
"validation": {
|
||||
"store": True,
|
||||
"url": KeyURLs.validations,
|
||||
"data": {"event_code": f"{KeyBases.create_key}", "asked_field": KeyValidations.validation },
|
||||
},
|
||||
"headers": {
|
||||
"store": True,
|
||||
"url": KeyURLs.validations,
|
||||
"data": {"event_code": f"{KeyBases.create_key}", "asked_field": KeyValidations.headers},
|
||||
},
|
||||
},
|
||||
},
|
||||
page_info={
|
||||
"en": {
|
||||
"page": "Create Account Records for reaching user all types account information",
|
||||
},
|
||||
"tr": {
|
||||
"page": "Kullanıcı tüm hesap bilgilerine ulaşmak için Hesap Kayıt Oluştur",
|
||||
},
|
||||
},
|
||||
endpoints={
|
||||
str(KeyBases.create_key): AccountRecordsCreateEventMethods.retrieve_all_event_keys(),
|
||||
},
|
||||
language_models={
|
||||
str(KeyBases.create_key): account_language_create_models_as_dict,
|
||||
},
|
||||
)
|
||||
|
||||
update_page_info = PageInfo(
|
||||
name=f"{cluster_name}",
|
||||
url=PageBases.UPDATE,
|
||||
icon=icon,
|
||||
instructions={
|
||||
str(KeyBases.update_key): {
|
||||
"validation": {
|
||||
"store": True,
|
||||
"url": KeyURLs.validations,
|
||||
"data": {"event_code": f"{KeyBases.update_key}", "asked_field": KeyValidations.validation},
|
||||
},
|
||||
"headers": {
|
||||
"store": True,
|
||||
"url": KeyURLs.validations,
|
||||
"data": {"event_code": f"{KeyBases.update_key}", "asked_field": KeyValidations.headers},
|
||||
},
|
||||
},
|
||||
},
|
||||
page_info={
|
||||
"en": {
|
||||
"page": "Update Account Records via all types account information",
|
||||
},
|
||||
"tr": {
|
||||
"page": "Tüm hesap bilgileri aracılığıyla Hesap Kayıtlarını Güncelle",
|
||||
},
|
||||
},
|
||||
endpoints={
|
||||
str(KeyBases.update_key): AccountRecordsUpdateEventMethods.retrieve_all_event_keys(),
|
||||
},
|
||||
language_models={
|
||||
str(KeyBases.update_key): account_language_update_form_models_as_dict,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
# Page Variations of the cluster
|
||||
page_infos = {
|
||||
ClustersPageInfo.dashboard_page_info.URL: ClustersPageInfo.dashboard_page_info,
|
||||
ClustersPageInfo.create_page_info.URL: ClustersPageInfo.create_page_info,
|
||||
ClustersPageInfo.update_page_info.URL: ClustersPageInfo.update_page_info,
|
||||
}
|
||||
|
||||
|
||||
# Check if all the page info is implemented in the mappings
|
||||
for t in [x for k, x in PageBases.__dict__.items() if not str(k).startswith("__")]:
|
||||
if t not in list(dict(page_infos).keys()):
|
||||
raise NotImplementedError(f"Page Info of : {t} is not implemented in mappings")
|
||||
78
Events/AllEvents/events/account/lang_models.py
Normal file
78
Events/AllEvents/events/account/lang_models.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from Events.Engine.abstract_class import DefaultClusterName, LanguageModels
|
||||
from .bases import KeyBases, cluster_name
|
||||
|
||||
|
||||
account_language_update_models = LanguageModels()
|
||||
account_language_update_models.COMPONENT = "Link"
|
||||
account_language_update_models.SITE_URL = f"/update?{DefaultClusterName}={cluster_name}"
|
||||
account_language_update_models.PREFIX_URL = (
|
||||
KeyBases.update_key
|
||||
)
|
||||
account_language_update_models.PAGE_INFO = {
|
||||
"en": {
|
||||
"page": "Update Account Records",
|
||||
},
|
||||
"tr": {
|
||||
"page": "Hesap Kayıdı Güncelle",
|
||||
},
|
||||
}
|
||||
account_language_model_as_dict = account_language_update_models.as_dict()
|
||||
|
||||
|
||||
account_language_created_models = LanguageModels()
|
||||
account_language_created_models.COMPONENT = "Link"
|
||||
account_language_created_models.SITE_URL = f"/create?{DefaultClusterName}={cluster_name}"
|
||||
account_language_created_models.PREFIX_URL = (
|
||||
KeyBases.create_key
|
||||
)
|
||||
account_language_created_models.PAGE_INFO = {
|
||||
"en": {
|
||||
"page": "Create Account Records",
|
||||
},
|
||||
"tr": {"page": "Hesap Kayıdı Oluştur"},
|
||||
}
|
||||
account_language_created_models_as_dict = account_language_created_models.as_dict()
|
||||
|
||||
account_language_list_models = LanguageModels()
|
||||
account_language_list_models.COMPONENT = "Table"
|
||||
account_language_list_models.SITE_URL = f"/dashboard?{DefaultClusterName}={cluster_name}"
|
||||
account_language_list_models.PREFIX_URL = (
|
||||
KeyBases.list_key
|
||||
)
|
||||
account_language_list_models.PAGE_INFO = {
|
||||
"en": {
|
||||
"page": "List Account Records",
|
||||
},
|
||||
"tr": {
|
||||
"page": "Hesap Kayıtlarını Listele",
|
||||
},
|
||||
}
|
||||
|
||||
account_language_list_models_as_dict = account_language_list_models.as_dict()
|
||||
|
||||
account_language_create_form_models = LanguageModels()
|
||||
account_language_create_form_models.COMPONENT = "Form"
|
||||
account_language_create_form_models.SITE_URL = f"/create?{DefaultClusterName}={cluster_name}"
|
||||
account_language_create_form_models.PREFIX_URL = (
|
||||
KeyBases.create_key
|
||||
)
|
||||
account_language_create_form_models.PAGE_INFO = {
|
||||
"en": {"page": "List Account Records", "button:": "Create"},
|
||||
"tr": {"page": "Hesap Kayıtlarını Listele", "button:": "Oluştur"},
|
||||
}
|
||||
|
||||
account_language_create_models_as_dict = account_language_create_form_models.as_dict()
|
||||
|
||||
account_language_update_form_models = LanguageModels()
|
||||
account_language_update_form_models.COMPONENT = "Form"
|
||||
account_language_update_form_models.SITE_URL = f"/update?{DefaultClusterName}={cluster_name}"
|
||||
account_language_update_form_models.PREFIX_URL = (
|
||||
KeyBases.update_key
|
||||
)
|
||||
account_language_update_form_models.PAGE_INFO = {
|
||||
"en": {"page": "Update Account Records", "button:": "Update"},
|
||||
"tr": {"page": "Hesap Kayıdı Güncelle", "button:": "Güncelle"},
|
||||
}
|
||||
account_language_update_form_models_as_dict = (
|
||||
account_language_update_form_models.as_dict()
|
||||
)
|
||||
97
Events/AllEvents/events/account/models.py
Normal file
97
Events/AllEvents/events/account/models.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""
|
||||
Account records request and response models.
|
||||
"""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import PydanticBaseModel, ListOptions
|
||||
|
||||
|
||||
class InsertAccountRecord(PydanticBaseModel):
|
||||
|
||||
iban: str
|
||||
bank_date: str
|
||||
currency_value: float
|
||||
bank_balance: float
|
||||
currency: str
|
||||
additional_balance: float
|
||||
channel_branch: str
|
||||
process_name: str
|
||||
process_type: str
|
||||
process_comment: str
|
||||
bank_reference_code: str
|
||||
|
||||
add_comment_note: Optional[str] = None
|
||||
is_receipt_mail_send: Optional[bool] = None
|
||||
found_from: Optional[str] = None
|
||||
similarity: Optional[float] = None
|
||||
remainder_balance: Optional[float] = None
|
||||
bank_date_y: Optional[int] = None
|
||||
bank_date_m: Optional[int] = None
|
||||
bank_date_w: Optional[int] = None
|
||||
bank_date_d: Optional[int] = None
|
||||
approving_accounting_record: Optional[bool] = None
|
||||
accounting_receipt_date: Optional[str] = None
|
||||
accounting_receipt_number: Optional[int] = None
|
||||
approved_record: Optional[bool] = None
|
||||
import_file_name: Optional[str] = None
|
||||
# receive_debit_uu_id: Optional[str] = None
|
||||
budget_type_uu_id: Optional[str] = None
|
||||
company_uu_id: Optional[str] = None
|
||||
send_company_uu_id: Optional[str] = None
|
||||
customer_id: Optional[str] = None
|
||||
customer_uu_id: Optional[str] = None
|
||||
send_person_uu_id: Optional[str] = None
|
||||
approving_accounting_person_uu_id: Optional[str] = None
|
||||
build_parts_uu_id: Optional[str] = None
|
||||
build_decision_book_uu_id: Optional[str] = None
|
||||
|
||||
|
||||
class UpdateAccountRecord(PydanticBaseModel):
|
||||
|
||||
iban: Optional[str] = None
|
||||
bank_date: Optional[str] = None
|
||||
currency_value: Optional[float] = None
|
||||
bank_balance: Optional[float] = None
|
||||
currency: Optional[str] = None
|
||||
additional_balance: Optional[float] = None
|
||||
channel_branch: Optional[str] = None
|
||||
process_name: Optional[str] = None
|
||||
process_type: Optional[str] = None
|
||||
process_comment: Optional[str] = None
|
||||
bank_reference_code: Optional[str] = None
|
||||
|
||||
add_comment_note: Optional[str] = None
|
||||
is_receipt_mail_send: Optional[bool] = None
|
||||
found_from: Optional[str] = None
|
||||
similarity: Optional[float] = None
|
||||
remainder_balance: Optional[float] = None
|
||||
bank_date_y: Optional[int] = None
|
||||
bank_date_m: Optional[int] = None
|
||||
bank_date_w: Optional[int] = None
|
||||
bank_date_d: Optional[int] = None
|
||||
approving_accounting_record: Optional[bool] = None
|
||||
accounting_receipt_date: Optional[str] = None
|
||||
accounting_receipt_number: Optional[int] = None
|
||||
approved_record: Optional[bool] = None
|
||||
import_file_name: Optional[str] = None
|
||||
receive_debit_uu_id: Optional[str] = None
|
||||
budget_type_uu_id: Optional[str] = None
|
||||
company_uu_id: Optional[str] = None
|
||||
send_company_uu_id: Optional[str] = None
|
||||
customer_id: Optional[str] = None
|
||||
customer_uu_id: Optional[str] = None
|
||||
send_person_uu_id: Optional[str] = None
|
||||
approving_accounting_person_uu_id: Optional[str] = None
|
||||
build_parts_uu_id: Optional[str] = None
|
||||
build_decision_book_uu_id: Optional[str] = None
|
||||
|
||||
|
||||
class ListAccountRecord(ListOptions):
|
||||
pass
|
||||
|
||||
|
||||
class AccountRequestValidators:
|
||||
InsertAccountRecord = InsertAccountRecord
|
||||
UpdateAccountRecord = UpdateAccountRecord
|
||||
ListAccountRecord = ListAccountRecord
|
||||
166
Events/AllEvents/events/address/address.py
Normal file
166
Events/AllEvents/events/address/address.py
Normal file
@@ -0,0 +1,166 @@
|
||||
"""
|
||||
Account related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
from fastapi import Request
|
||||
|
||||
from Events.Engine.abstract_class import MethodToEvent
|
||||
from Events.base_request_model import EndpointBaseRequestModel, ContextRetrievers
|
||||
|
||||
from ApiLayers.Middleware.token_event_middleware import TokenEventMiddleware
|
||||
from ApiLayers.ApiValidations.Response.default_response import (
|
||||
EndpointSuccessListResponse,
|
||||
)
|
||||
|
||||
from .function_handlers import (
|
||||
AddressListFunctions,
|
||||
AddressUpdateFunctions,
|
||||
AddressSearchFunctions,
|
||||
AddressCreateFunctions,
|
||||
)
|
||||
from .api_events import AddressSuperUserEvents
|
||||
|
||||
|
||||
AddressListEventMethods = MethodToEvent(
|
||||
name="AddressListEventMethods",
|
||||
events={
|
||||
AddressSuperUserEvents.AddressListEvents.key: AddressSuperUserEvents.AddressListEvents,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/list",
|
||||
method="POST",
|
||||
summary="List all accounts by given previligous",
|
||||
description="List all accounts by given previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_list_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_list_event_endpoint)
|
||||
event_2_catch = AddressListEventMethods.retrieve_event(
|
||||
event_function_code=f"{AddressSuperUserEvents.AddressListEvents.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AddressListFunctions.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AddressListEventMethods.endpoint_callable = account_list_event_endpoint
|
||||
|
||||
|
||||
AddressCreateEventMethods = MethodToEvent(
|
||||
name="AddressCreateEventMethods",
|
||||
events={
|
||||
AddressSuperUserEvents.AddressCreateEvents.key: AddressSuperUserEvents.AddressCreateEvents,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/create",
|
||||
method="POST",
|
||||
summary="Create Address via given data and previligous",
|
||||
description="Create Address via given data and previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_create_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_create_event_endpoint)
|
||||
event_2_catch = AddressCreateEventMethods.retrieve_event(
|
||||
event_function_code=f"{AddressSuperUserEvents.AddressCreateEvents.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AddressCreateFunctions.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AddressCreateEventMethods.endpoint_callable = account_create_event_endpoint
|
||||
|
||||
|
||||
AddressUpdateEventMethods = MethodToEvent(
|
||||
name="AddressUpdateEventMethods",
|
||||
events={
|
||||
AddressSuperUserEvents.AddressUpdateEvents.key: AddressSuperUserEvents.AddressUpdateEvents,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/update",
|
||||
method="POST",
|
||||
summary="Update Address via given data and previligous",
|
||||
description="Update Address via given data and previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_update_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_update_event_endpoint)
|
||||
event_2_catch = AddressUpdateEventMethods.retrieve_event(
|
||||
event_function_code=f"{AddressSuperUserEvents.AddressUpdateEvents.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AddressUpdateFunctions.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AddressUpdateEventMethods.endpoint_callable = account_update_event_endpoint
|
||||
|
||||
|
||||
AddressSearchEventMethods = MethodToEvent(
|
||||
name="AddressSearchEventMethods",
|
||||
events={
|
||||
AddressSuperUserEvents.AddressSearchEvents.key: AddressSuperUserEvents.AddressSearchEvents,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/search",
|
||||
method="POST",
|
||||
summary="Search Address via given data and previligous",
|
||||
description="Search Address via given data and previligous",
|
||||
)
|
||||
|
||||
|
||||
def address_search_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_update_event_endpoint)
|
||||
event_2_catch = AddressUpdateEventMethods.retrieve_event(
|
||||
event_function_code=f"{AddressSuperUserEvents.AddressSearchEvents.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
AddressSearchFunctions.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
AddressSearchEventMethods.endpoint_callable = address_search_event_endpoint
|
||||
85
Events/AllEvents/events/address/api_events.py
Normal file
85
Events/AllEvents/events/address/api_events.py
Normal file
@@ -0,0 +1,85 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
# from models import TemplateResponseModels, TemplateRequestModels
|
||||
from .function_handlers import AddressSuperUserFunctions
|
||||
|
||||
|
||||
# Address List for super_user event
|
||||
address_list_super_user_event = Event(
|
||||
name="account_insert_super_user_event",
|
||||
key="7ce855ce-db79-4397-b0ec-f5e408ea6447",
|
||||
# request_validator=AccountRequestValidators.ListAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="",
|
||||
description="List address by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
address_list_super_user_event.endpoint_callable = (
|
||||
AddressSuperUserFunctions.AddressListFunctions.template_example_function_list
|
||||
)
|
||||
|
||||
# Address Create for super_user event
|
||||
address_create_super_user_event = Event(
|
||||
name="account_insert_super_user_event",
|
||||
key="d638a6b2-cf2e-4361-99a4-021183b75ec1",
|
||||
# request_validator=AccountRequestValidators.ListAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="",
|
||||
description="Create address by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
address_create_super_user_event.endpoint_callable = (
|
||||
AddressSuperUserFunctions.AddressCreateFunctions.template_example_function_list
|
||||
)
|
||||
|
||||
|
||||
# Address Update for super_user event
|
||||
address_update_super_user_event = Event(
|
||||
name="account_insert_super_user_event",
|
||||
key="455b8bf5-52e4-47fa-9338-102bfcd364e5",
|
||||
# request_validator=AccountRequestValidators.ListAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="",
|
||||
description="Update address by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
address_update_super_user_event.endpoint_callable = (
|
||||
AddressSuperUserFunctions.AddressUpdateFunctions.template_example_function_list
|
||||
)
|
||||
|
||||
|
||||
# Address Update for super_user event
|
||||
address_search_super_user_event = Event(
|
||||
name="account_insert_super_user_event",
|
||||
key="7dd8c122-fae5-4a6d-a439-068312bb4df3",
|
||||
# request_validator=AccountRequestValidators.ListAccountRecord,
|
||||
# response_validator=SelectResponseAccount,
|
||||
# language_models=[AccountRecords.__language_model__],
|
||||
language_models=[],
|
||||
statics="",
|
||||
description="Search address by validation list options and queries.",
|
||||
)
|
||||
|
||||
|
||||
address_search_super_user_event.endpoint_callable = (
|
||||
AddressSuperUserFunctions.AddressSearchFunctions.template_example_function_list
|
||||
)
|
||||
|
||||
|
||||
class AddressSuperUserEvents:
|
||||
AddressListEvents = address_list_super_user_event
|
||||
AddressCreateEvents = address_create_super_user_event
|
||||
AddressUpdateEvents = address_update_super_user_event
|
||||
AddressSearchEvents = address_search_super_user_event
|
||||
27
Events/AllEvents/events/address/cluster.py
Normal file
27
Events/AllEvents/events/address/cluster.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
|
||||
from .address import (
|
||||
AddressListEventMethods,
|
||||
AddressCreateEventMethods,
|
||||
AddressUpdateEventMethods,
|
||||
AddressSearchEventMethods,
|
||||
)
|
||||
from .info import address_page_info
|
||||
|
||||
|
||||
AddressCluster = CategoryCluster(
|
||||
name="AddressCluster",
|
||||
tags=["Address"],
|
||||
prefix="/address",
|
||||
description="Address Cluster",
|
||||
pageinfo=address_page_info,
|
||||
endpoints={
|
||||
"AddressListEventMethods": AddressListEventMethods,
|
||||
"AddressCreateEventMethods": AddressCreateEventMethods,
|
||||
"AddressUpdateEventMethods": AddressUpdateEventMethods,
|
||||
"AddressSearchEventMethods": AddressSearchEventMethods,
|
||||
},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
is_client=True,
|
||||
)
|
||||
157
Events/AllEvents/events/address/function_handlers.py
Normal file
157
Events/AllEvents/events/address/function_handlers.py
Normal file
@@ -0,0 +1,157 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class AddressListFunctions(BaseRouteModel):
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
|
||||
|
||||
class AddressCreateFunctions(BaseRouteModel):
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
|
||||
|
||||
class AddressSearchFunctions(BaseRouteModel):
|
||||
"""Event methods for searching addresses.
|
||||
|
||||
This class handles address search functionality including text search
|
||||
and filtering.
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
|
||||
|
||||
class AddressUpdateFunctions(BaseRouteModel):
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
|
||||
|
||||
class AddressSuperUserFunctions:
|
||||
AddressListFunctions = AddressListFunctions
|
||||
AddressCreateFunctions = AddressCreateFunctions
|
||||
AddressSearchFunctions = AddressSearchFunctions
|
||||
AddressUpdateFunctions = AddressUpdateFunctions
|
||||
77
Events/AllEvents/events/address/info.py
Normal file
77
Events/AllEvents/events/address/info.py
Normal file
@@ -0,0 +1,77 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
from .address import (
|
||||
AddressListEventMethods,
|
||||
AddressCreateEventMethods,
|
||||
AddressUpdateEventMethods,
|
||||
AddressSearchEventMethods,
|
||||
)
|
||||
|
||||
prefix = "/address"
|
||||
cluster_name = "AddressCluster"
|
||||
address_page_info = PageInfo(
|
||||
name=f"{cluster_name}",
|
||||
url=f"/dashboard?site={cluster_name}",
|
||||
icon="Building",
|
||||
endpoints={
|
||||
str(
|
||||
f"{prefix}{AddressUpdateEventMethods.URL}"
|
||||
): AddressUpdateEventMethods.retrieve_all_event_keys(),
|
||||
str(
|
||||
f"{prefix}{AddressCreateEventMethods.URL}"
|
||||
): AddressCreateEventMethods.retrieve_all_event_keys(),
|
||||
str(
|
||||
f"{prefix}{AddressSearchEventMethods.URL}"
|
||||
): AddressSearchEventMethods.retrieve_all_event_keys(),
|
||||
str(
|
||||
f"{prefix}{AddressListEventMethods.URL}"
|
||||
): AddressListEventMethods.retrieve_all_event_keys(),
|
||||
},
|
||||
language_models={
|
||||
"page_info": {
|
||||
"key": "pair", # key: pair, value: dict
|
||||
"description": {
|
||||
"en": "Account Records for reaching user all types account information",
|
||||
"tr": "Kullanıcı tüm hesap bilgilerine ulaşmak için Hesap Kayıtları",
|
||||
},
|
||||
},
|
||||
f"{prefix}{AddressUpdateEventMethods.URL}": {
|
||||
"component": "Button",
|
||||
"site_url": f"/update?site={cluster_name}",
|
||||
"page_info": {
|
||||
"text": {
|
||||
"en": "Update Account Records",
|
||||
"tr": "Hesap Kayıdı Güncelle",
|
||||
},
|
||||
},
|
||||
},
|
||||
f"{prefix}{AddressCreateEventMethods.URL}": {
|
||||
"component": "Button",
|
||||
"site_url": f"/create?site={cluster_name}",
|
||||
"page_info": {
|
||||
"text": {
|
||||
"en": "Create Account Records",
|
||||
"tr": "Hesap Kayıdı Oluştur",
|
||||
},
|
||||
},
|
||||
},
|
||||
f"{prefix}{AddressSearchEventMethods.URL}": {
|
||||
"component": "Search",
|
||||
"page_info": {
|
||||
"text": {
|
||||
"en": "Search Account Records",
|
||||
"tr": "Hesap Kayıtlarını Ara",
|
||||
},
|
||||
},
|
||||
},
|
||||
f"{prefix}{AddressListEventMethods.URL}": {
|
||||
"component": "Table",
|
||||
"fetch_url": AddressListEventMethods.URL,
|
||||
"page_info": {
|
||||
"description": {
|
||||
"en": "Account Records for reaching user all types account information",
|
||||
"tr": "Kullanıcı tüm hesap bilgilerine ulaşmak için Hesap Kayıtları",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
0
Events/AllEvents/events/address/models.py
Normal file
0
Events/AllEvents/events/address/models.py
Normal file
21
Events/AllEvents/events/building/build_area/api_events.py
Normal file
21
Events/AllEvents/events/building/build_area/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/building/build_area/cluster.py
Normal file
14
Events/AllEvents/events/building/build_area/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/building/build_area/info.py
Normal file
11
Events/AllEvents/events/building/build_area/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/building/build_parts/api_events.py
Normal file
21
Events/AllEvents/events/building/build_parts/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/building/build_parts/cluster.py
Normal file
14
Events/AllEvents/events/building/build_parts/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/building/build_parts/info.py
Normal file
11
Events/AllEvents/events/building/build_parts/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/building/build_sites/api_events.py
Normal file
21
Events/AllEvents/events/building/build_sites/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/building/build_sites/cluster.py
Normal file
14
Events/AllEvents/events/building/build_sites/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/building/build_sites/info.py
Normal file
11
Events/AllEvents/events/building/build_sites/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/building/build_types/api_events.py
Normal file
21
Events/AllEvents/events/building/build_types/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/building/build_types/cluster.py
Normal file
14
Events/AllEvents/events/building/build_types/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/building/build_types/info.py
Normal file
11
Events/AllEvents/events/building/build_types/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
25
Events/AllEvents/events/building/building/api_events.py
Normal file
25
Events/AllEvents/events/building/building/api_events.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
# from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
building_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
# request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
statics="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
building_event.endpoint_callable = TemplateFunctions.template_example_function_list
|
||||
|
||||
|
||||
class BuildingSuperUserEvents:
|
||||
BuildingEvent = building_event
|
||||
58
Events/AllEvents/events/building/building/building.py
Normal file
58
Events/AllEvents/events/building/building/building.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""
|
||||
Account related API endpoints.
|
||||
"""
|
||||
|
||||
from typing import Any, Dict
|
||||
from fastapi import Request
|
||||
|
||||
from Events.Engine.abstract_class import MethodToEvent
|
||||
from Events.base_request_model import EndpointBaseRequestModel, ContextRetrievers
|
||||
|
||||
from ApiLayers.Middleware.token_event_middleware import TokenEventMiddleware
|
||||
from ApiLayers.ApiValidations.Response.default_response import (
|
||||
EndpointSuccessListResponse,
|
||||
)
|
||||
|
||||
# from .function_handlers import (
|
||||
# AddressListFunctions,
|
||||
# AddressUpdateFunctions,
|
||||
# AddressSearchFunctions,
|
||||
# AddressCreateFunctions,
|
||||
# )
|
||||
from .api_events import BuildingSuperUserEvents
|
||||
|
||||
|
||||
BuildingListEventMethods = MethodToEvent(
|
||||
name="BuildingListEventMethods",
|
||||
events={
|
||||
BuildingSuperUserEvents.BuildingEvent.key: BuildingSuperUserEvents.BuildingEvent,
|
||||
},
|
||||
headers=[],
|
||||
errors=[],
|
||||
decorators_list=[TokenEventMiddleware.event_required],
|
||||
url="/list",
|
||||
method="POST",
|
||||
summary="List all accounts by given previligous",
|
||||
description="List all accounts by given previligous",
|
||||
)
|
||||
|
||||
|
||||
def account_list_event_endpoint(
|
||||
request: Request, data: EndpointBaseRequestModel
|
||||
) -> Dict[str, Any]:
|
||||
context_retriever = ContextRetrievers(func=account_list_event_endpoint)
|
||||
event_2_catch = BuildingListEventMethods.retrieve_event(
|
||||
event_function_code=f"{BuildingSuperUserEvents.BuildingEvent.key}"
|
||||
)
|
||||
context_retriever.RESPONSE_VALIDATOR = event_2_catch.RESPONSE_VALIDATOR
|
||||
data = event_2_catch.REQUEST_VALIDATOR(**data.data)
|
||||
BuildingListFunctions.context_retriever = context_retriever
|
||||
pagination_result = event_2_catch.endpoint_callable(data=data)
|
||||
return EndpointSuccessListResponse(
|
||||
code=event_2_catch.static_key, lang=context_retriever.token.lang
|
||||
).as_dict(
|
||||
data=pagination_result.data, pagination=pagination_result.pagination.as_dict()
|
||||
)
|
||||
|
||||
|
||||
BuildingListEventMethods.endpoint_callable = account_list_event_endpoint
|
||||
15
Events/AllEvents/events/building/building/cluster.py
Normal file
15
Events/AllEvents/events/building/building/cluster.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
|
||||
from .info import building_page_info
|
||||
|
||||
|
||||
BuildingCluster = CategoryCluster(
|
||||
name="BuildingCluster",
|
||||
tags=["Building"],
|
||||
prefix="/building",
|
||||
description="Building Cluster",
|
||||
pageinfo=building_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
42
Events/AllEvents/events/building/building/info.py
Normal file
42
Events/AllEvents/events/building/building/info.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
from Events.Engine.abstract_class import PageComponent
|
||||
|
||||
|
||||
create_building = PageComponent(
|
||||
name="CreateBuilding",
|
||||
url="/create",
|
||||
language_models={
|
||||
"en": "Create Building",
|
||||
"tr": "Bina Oluştur",
|
||||
},
|
||||
)
|
||||
|
||||
update_building = PageComponent(
|
||||
name="UpdateBuilding",
|
||||
url="/update",
|
||||
language_models={
|
||||
"en": "Update Building",
|
||||
"tr": "Bina Güncelle",
|
||||
},
|
||||
)
|
||||
|
||||
list_building = PageComponent(
|
||||
name="ListBuilding",
|
||||
url="/dashboard",
|
||||
language_models={
|
||||
"en": "List Building",
|
||||
"tr": "Bina Listele",
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
building_page_info = PageInfo(
|
||||
name="BuildingCluster",
|
||||
language_models={
|
||||
"en": {},
|
||||
"tr": {},
|
||||
},
|
||||
icon="Building",
|
||||
sub_components=[create_building, update_building, list_building],
|
||||
url="/dashboard?site=AddressCluster",
|
||||
)
|
||||
325
Events/AllEvents/events/building/building/models.py
Normal file
325
Events/AllEvents/events/building/building/models.py
Normal file
@@ -0,0 +1,325 @@
|
||||
"""
|
||||
request models.
|
||||
"""
|
||||
|
||||
from typing import TYPE_CHECKING, Dict, Any, Literal, Optional, TypedDict, Union
|
||||
from pydantic import BaseModel, Field, model_validator, RootModel, ConfigDict
|
||||
from ApiEvents.base_request_model import BaseRequestModel, DictRequestModel
|
||||
from ApiValidations.Custom.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from ApiValidations.Request.base_validations import ListOptions
|
||||
from ErrorHandlers.Exceptions.api_exc import HTTPExceptionApi
|
||||
from Schemas.identity.identity import (
|
||||
AddressPostcode,
|
||||
Addresses,
|
||||
RelationshipEmployee2PostCode,
|
||||
)
|
||||
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from fastapi import Request
|
||||
|
||||
|
||||
class AddressListEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "SELECT"
|
||||
event_description = "List Address records"
|
||||
event_category = "Address"
|
||||
|
||||
__event_keys__ = {
|
||||
"9c251d7d-da70-4d63-a72c-e69c26270442": "address_list_super_user",
|
||||
"52afe375-dd95-4f4b-aaa2-4ec61bc6de52": "address_list_employee",
|
||||
}
|
||||
__event_validation__ = {
|
||||
"9c251d7d-da70-4d63-a72c-e69c26270442": ListAddressResponse,
|
||||
"52afe375-dd95-4f4b-aaa2-4ec61bc6de52": ListAddressResponse,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def address_list_super_user(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
db = RelationshipEmployee2PostCode.new_session()
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.company_id
|
||||
== token_dict.selected_company.company_id,
|
||||
db=db,
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
raise HTTPExceptionApi(
|
||||
status_code=404,
|
||||
detail="User has no post code registered. User can not list addresses.",
|
||||
)
|
||||
get_street_ids = [
|
||||
street_id[0]
|
||||
for street_id in AddressPostcode.select_only(
|
||||
AddressPostcode.id.in_(post_code_id_list),
|
||||
select_args=[AddressPostcode.street_id],
|
||||
order_by=AddressPostcode.street_id.desc(),
|
||||
).data
|
||||
]
|
||||
if not get_street_ids:
|
||||
raise HTTPExceptionApi(
|
||||
status_code=404,
|
||||
detail="User has no street registered. User can not list addresses.",
|
||||
)
|
||||
Addresses.pre_query = Addresses.filter_all(
|
||||
Addresses.street_id.in_(get_street_ids),
|
||||
).query
|
||||
Addresses.filter_attr = list_options
|
||||
records = Addresses.filter_all().data
|
||||
return
|
||||
# return AlchemyJsonResponse(
|
||||
# completed=True, message="List Address records", result=records
|
||||
# )
|
||||
|
||||
@classmethod
|
||||
def address_list_employee(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
Addresses.filter_attr = list_options
|
||||
Addresses.pre_query = Addresses.filter_all(
|
||||
Addresses.street_id.in_(get_street_ids),
|
||||
)
|
||||
records = Addresses.filter_all().data
|
||||
return
|
||||
# return AlchemyJsonResponse(
|
||||
# completed=True, message="List Address records", result=records
|
||||
# )
|
||||
|
||||
|
||||
class AddressCreateEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "CREATE"
|
||||
event_description = ""
|
||||
event_category = ""
|
||||
|
||||
__event_keys__ = {
|
||||
"ffdc445f-da10-4ce4-9531-d2bdb9a198ae": "create_address",
|
||||
}
|
||||
__event_validation__ = {
|
||||
"ffdc445f-da10-4ce4-9531-d2bdb9a198ae": InsertAddress,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def create_address(
|
||||
cls,
|
||||
data: InsertAddress,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
post_code = AddressPostcode.filter_one(
|
||||
AddressPostcode.uu_id == data.post_code_uu_id,
|
||||
).data
|
||||
if not post_code:
|
||||
raise HTTPExceptionApi(
|
||||
status_code=404,
|
||||
detail="Post code not found. User can not create address without post code.",
|
||||
)
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
data_dict["street_id"] = post_code.street_id
|
||||
data_dict["street_uu_id"] = str(post_code.street_uu_id)
|
||||
del data_dict["post_code_uu_id"]
|
||||
address = Addresses.find_or_create(**data_dict)
|
||||
address.save()
|
||||
address.update(is_confirmed=True)
|
||||
address.save()
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Address created successfully",
|
||||
result=address.get_dict(),
|
||||
)
|
||||
|
||||
|
||||
class AddressSearchEventMethods(MethodToEvent):
|
||||
"""Event methods for searching addresses.
|
||||
|
||||
This class handles address search functionality including text search
|
||||
and filtering.
|
||||
"""
|
||||
|
||||
event_type = "SEARCH"
|
||||
event_description = "Search for addresses using text and filters"
|
||||
event_category = "Address"
|
||||
|
||||
__event_keys__ = {
|
||||
"e0ac1269-e9a7-4806-9962-219ac224b0d0": "search_address",
|
||||
}
|
||||
__event_validation__ = {
|
||||
"e0ac1269-e9a7-4806-9962-219ac224b0d0": SearchAddress,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def _build_order_clause(
|
||||
cls, filter_list: Dict[str, Any], schemas: List[str], filter_table: Any
|
||||
) -> Any:
|
||||
"""Build the ORDER BY clause for the query.
|
||||
|
||||
Args:
|
||||
filter_list: Dictionary of filter options
|
||||
schemas: List of available schema fields
|
||||
filter_table: SQLAlchemy table to query
|
||||
|
||||
Returns:
|
||||
SQLAlchemy order_by clause
|
||||
"""
|
||||
# Default to ordering by UUID if field not in schema
|
||||
if filter_list.get("order_field") not in schemas:
|
||||
filter_list["order_field"] = "uu_id"
|
||||
else:
|
||||
# Extract table and field from order field
|
||||
table_name, field_name = str(filter_list.get("order_field")).split(".")
|
||||
filter_table = getattr(databases.sql_models, table_name)
|
||||
filter_list["order_field"] = field_name
|
||||
|
||||
# Build order clause
|
||||
field = getattr(filter_table, filter_list.get("order_field"))
|
||||
return (
|
||||
field.desc()
|
||||
if str(filter_list.get("order_type"))[0] == "d"
|
||||
else field.asc()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def _format_record(cls, record: Any, schemas: List[str]) -> Dict[str, str]:
|
||||
"""Format a database record into a dictionary.
|
||||
|
||||
Args:
|
||||
record: Database record to format
|
||||
schemas: List of schema fields
|
||||
|
||||
Returns:
|
||||
Formatted record dictionary
|
||||
"""
|
||||
result = {}
|
||||
for index, schema in enumerate(schemas):
|
||||
value = str(record[index])
|
||||
# Special handling for UUID fields
|
||||
if "uu_id" in value:
|
||||
value = str(value)
|
||||
result[schema] = value
|
||||
return result
|
||||
|
||||
@classmethod
|
||||
def search_address(
|
||||
cls,
|
||||
data: SearchAddress,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
) -> JSONResponse:
|
||||
"""Search for addresses using text search and filters.
|
||||
|
||||
Args:
|
||||
data: Search parameters including text and filters
|
||||
token_dict: Authentication token
|
||||
|
||||
Returns:
|
||||
JSON response with search results
|
||||
|
||||
Raises:
|
||||
HTTPExceptionApi: If search fails
|
||||
"""
|
||||
try:
|
||||
# Start performance measurement
|
||||
start_time = perf_counter()
|
||||
|
||||
# Get initial query
|
||||
search_result = AddressStreet.search_address_text(search_text=data.search)
|
||||
if not search_result:
|
||||
raise HTTPExceptionApi(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="No addresses found matching search criteria",
|
||||
)
|
||||
|
||||
query = search_result.get("query")
|
||||
schemas = search_result.get("schema")
|
||||
|
||||
# Apply filters
|
||||
filter_list = data.list_options.dump()
|
||||
filter_table = AddressStreet
|
||||
|
||||
# Build and apply order clause
|
||||
order = cls._build_order_clause(filter_list, schemas, filter_table)
|
||||
|
||||
# Apply pagination
|
||||
page_size = int(filter_list.get("size"))
|
||||
offset = (int(filter_list.get("page")) - 1) * page_size
|
||||
|
||||
# Execute query
|
||||
query = (
|
||||
query.order_by(order)
|
||||
.limit(page_size)
|
||||
.offset(offset)
|
||||
.populate_existing()
|
||||
)
|
||||
records = list(query.all())
|
||||
|
||||
# Format results
|
||||
results = [cls._format_record(record, schemas) for record in records]
|
||||
|
||||
# Log performance
|
||||
duration = perf_counter() - start_time
|
||||
print(f"Address search completed in {duration:.3f}s")
|
||||
|
||||
return AlchemyJsonResponse(
|
||||
completed=True, message="Address search results", result=results
|
||||
)
|
||||
|
||||
except HTTPExceptionApi as e:
|
||||
# Re-raise HTTP exceptions
|
||||
raise e
|
||||
except Exception as e:
|
||||
# Log and wrap other errors
|
||||
print(f"Address search error: {str(e)}")
|
||||
raise HTTPExceptionApi(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail="Failed to search addresses",
|
||||
) from e
|
||||
|
||||
|
||||
class AddressUpdateEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "UPDATE"
|
||||
event_description = ""
|
||||
event_category = ""
|
||||
|
||||
__event_keys__ = {
|
||||
"1f9c3a9c-e5bd-4dcd-9b9a-3742d7e03a27": "update_address",
|
||||
}
|
||||
__event_validation__ = {
|
||||
"1f9c3a9c-e5bd-4dcd-9b9a-3742d7e03a27": UpdateAddress,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def update_address(
|
||||
cls,
|
||||
address_uu_id: str,
|
||||
data: UpdateAddress,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
if isinstance(token_dict, EmployeeTokenObject):
|
||||
address = Addresses.filter_one(
|
||||
Addresses.uu_id == address_uu_id,
|
||||
).data
|
||||
if not address:
|
||||
raise HTTPExceptionApi(
|
||||
status_code=404,
|
||||
detail=f"Address not found. User can not update with given address uuid : {address_uu_id}",
|
||||
)
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
updated_address = address.update(**data_dict)
|
||||
updated_address.save()
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Address updated successfully",
|
||||
result=updated_address.get_dict(),
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
raise HTTPExceptionApi(
|
||||
status_code=403,
|
||||
detail="Occupant can not update address.",
|
||||
)
|
||||
21
Events/AllEvents/events/building/living_spaces/api_events.py
Normal file
21
Events/AllEvents/events/building/living_spaces/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/building/living_spaces/cluster.py
Normal file
14
Events/AllEvents/events/building/living_spaces/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/building/living_spaces/info.py
Normal file
11
Events/AllEvents/events/building/living_spaces/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/company/company/api_events.py
Normal file
21
Events/AllEvents/events/company/company/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/company/company/cluster.py
Normal file
14
Events/AllEvents/events/company/company/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
0
Events/AllEvents/events/company/company/company.py
Normal file
0
Events/AllEvents/events/company/company/company.py
Normal file
78
Events/AllEvents/events/company/company/function_handlers.py
Normal file
78
Events/AllEvents/events/company/company/function_handlers.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/company/company/info.py
Normal file
11
Events/AllEvents/events/company/company/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/company/department/api_events.py
Normal file
21
Events/AllEvents/events/company/department/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/company/department/cluster.py
Normal file
14
Events/AllEvents/events/company/department/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/company/department/info.py
Normal file
11
Events/AllEvents/events/company/department/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/company/duties/api_events.py
Normal file
21
Events/AllEvents/events/company/duties/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/company/duties/cluster.py
Normal file
14
Events/AllEvents/events/company/duties/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
0
Events/AllEvents/events/company/duties/duties.py
Normal file
0
Events/AllEvents/events/company/duties/duties.py
Normal file
78
Events/AllEvents/events/company/duties/function_handlers.py
Normal file
78
Events/AllEvents/events/company/duties/function_handlers.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/company/duties/info.py
Normal file
11
Events/AllEvents/events/company/duties/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/company/duty/api_events.py
Normal file
21
Events/AllEvents/events/company/duty/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/company/duty/cluster.py
Normal file
14
Events/AllEvents/events/company/duty/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
0
Events/AllEvents/events/company/duty/duty.py
Normal file
0
Events/AllEvents/events/company/duty/duty.py
Normal file
78
Events/AllEvents/events/company/duty/function_handlers.py
Normal file
78
Events/AllEvents/events/company/duty/function_handlers.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/company/duty/info.py
Normal file
11
Events/AllEvents/events/company/duty/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/company/employee/api_events.py
Normal file
21
Events/AllEvents/events/company/employee/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/company/employee/cluster.py
Normal file
14
Events/AllEvents/events/company/employee/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/company/employee/info.py
Normal file
11
Events/AllEvents/events/company/employee/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
21
Events/AllEvents/events/company/staff/api_events.py
Normal file
21
Events/AllEvents/events/company/staff/api_events.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
14
Events/AllEvents/events/company/staff/cluster.py
Normal file
14
Events/AllEvents/events/company/staff/cluster.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
78
Events/AllEvents/events/company/staff/function_handlers.py
Normal file
78
Events/AllEvents/events/company/staff/function_handlers.py
Normal file
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/company/staff/info.py
Normal file
11
Events/AllEvents/events/company/staff/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
0
Events/AllEvents/events/company/staff/staff.py
Normal file
0
Events/AllEvents/events/company/staff/staff.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/decision_book/book_payment/info.py
Normal file
11
Events/AllEvents/events/decision_book/book_payment/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
11
Events/AllEvents/events/decision_book/decision_book/info.py
Normal file
11
Events/AllEvents/events/decision_book/decision_book/info.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
@@ -0,0 +1,14 @@
|
||||
from Events.Engine.abstract_class import CategoryCluster
|
||||
from info import template_page_info
|
||||
|
||||
|
||||
TemplateCluster = CategoryCluster(
|
||||
name="TemplateCluster",
|
||||
tags=["template"],
|
||||
prefix="/template",
|
||||
description="Template cluster",
|
||||
pageinfo=template_page_info,
|
||||
endpoints={},
|
||||
include_in_schema=True,
|
||||
sub_category=[],
|
||||
)
|
||||
@@ -0,0 +1,78 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from ApiLayers.ApiValidations.Request import ListOptions
|
||||
from Events.base_request_model import BaseRouteModel, ListOptionsBase
|
||||
from Services.PostgresDb.Models.pagination import PaginationResult
|
||||
|
||||
|
||||
class Handlers:
|
||||
"""Class for handling authentication functions"""
|
||||
|
||||
@classmethod # Requires no auth context
|
||||
def handle_function(cls, **kwargs):
|
||||
"""Handle function with kwargs"""
|
||||
return
|
||||
|
||||
|
||||
class TemplateFunctions(BaseRouteModel):
|
||||
"""
|
||||
Class for handling authentication functions
|
||||
Is a template 4 TokenMiddleware.event_required decorator function groups.
|
||||
results as :
|
||||
STATIC_MESSAGE & LANG retrieved from redis
|
||||
{
|
||||
"completed": true,
|
||||
"message": STATIC_MESSAGE,
|
||||
"lang": LANG,
|
||||
"pagination": {
|
||||
"size": 10,
|
||||
"page": 2,
|
||||
"allCount": 28366,
|
||||
"totalCount": 18,
|
||||
"totalPages": 2,
|
||||
"pageCount": 8,
|
||||
"orderField": ["type_code", "neighborhood_name"],
|
||||
"orderType": ["asc", "desc"]
|
||||
},
|
||||
"data": [
|
||||
{
|
||||
"created_at": "2025-01-12 09:39:48 +00:00",
|
||||
"active": true,
|
||||
"expiry_starts": "2025-01-12 09:39:48 +00:00",
|
||||
"locality_uu_id": "771fd152-aca1-4d75-a42e-9b29ea7112b5",
|
||||
"uu_id": "e1baa3bc-93ce-4099-a078-a11b71d3b1a8"
|
||||
},
|
||||
...
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def template_example_function_list(
|
||||
cls, data: Optional[Union[dict, ListOptions]]
|
||||
) -> PaginationResult:
|
||||
from ApiLayers.Schemas import AddressNeighborhood
|
||||
|
||||
list_options_base = ListOptionsBase(
|
||||
table=AddressNeighborhood,
|
||||
list_options=data,
|
||||
model_query=None,
|
||||
)
|
||||
db_session, query_options = list_options_base.init_list_options()
|
||||
if cls.context_retriever.token.is_occupant:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("10"),
|
||||
db=db_session,
|
||||
).query
|
||||
elif cls.context_retriever.token.is_employee:
|
||||
AddressNeighborhood.pre_query = AddressNeighborhood.filter_all(
|
||||
AddressNeighborhood.neighborhood_code.icontains("9"),
|
||||
db=db_session,
|
||||
).query
|
||||
records = AddressNeighborhood.filter_all(
|
||||
*query_options.convert(), db=db_session
|
||||
)
|
||||
return list_options_base.paginated_result(
|
||||
records=records,
|
||||
response_model=getattr(cls.context_retriever, "RESPONSE_VALIDATOR", None),
|
||||
)
|
||||
@@ -0,0 +1,11 @@
|
||||
from Events.Engine.abstract_class import PageInfo
|
||||
|
||||
|
||||
template_page_info = PageInfo(
|
||||
name="template",
|
||||
title={"en": "template"},
|
||||
description={"en": "template"},
|
||||
icon="",
|
||||
parent="",
|
||||
url="",
|
||||
)
|
||||
@@ -0,0 +1,21 @@
|
||||
from Events.Engine.abstract_class import Event
|
||||
from ApiLayers.LanguageModels.Request import (
|
||||
LoginRequestLanguageModel,
|
||||
)
|
||||
|
||||
from models import TemplateResponseModels, TemplateRequestModels
|
||||
from function_handlers import TemplateFunctions
|
||||
|
||||
|
||||
# Auth Login
|
||||
template_event = Event(
|
||||
name="authentication_login_super_user_event",
|
||||
key="a5d2d0d1-3e9b-4b0f-8c7d-6d4a4b4c4d4e",
|
||||
request_validator=TemplateRequestModels.TemplateRequestModelX,
|
||||
language_models=[LoginRequestLanguageModel],
|
||||
response_validation_static="LOGIN_SUCCESS",
|
||||
description="Login super user",
|
||||
)
|
||||
|
||||
|
||||
template_event.endpoint_callable = TemplateFunctions.template_example_function()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user