language models updated
This commit is contained in:
parent
bc300f727a
commit
e403993d24
|
|
@ -5,23 +5,28 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="b5202e0c-6ddf-4a56-a13a-e18798c4c7cf" name="Changes" comment="">
|
<list default="true" id="b5202e0c-6ddf-4a56-a13a-e18798c4c7cf" name="Changes" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/wag-managment-api-service-version-5.iml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/wag-managment-api-service-version-5.iml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/ApiLayers/AllConfigs/Redis/configs.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/AllConfigs/Redis/configs.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/ApiLayers/ApiServices/Login/user_login_handler.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ApiServices/Login/user_login_handler.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/ApiLayers/ApiServices/Login/user_login_handler.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ApiServices/Login/user_login_handler.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/ApiLayers/ApiServices/Token/token_handler.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ApiServices/Token/token_handler.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/ApiLayers/ApiValidations/Response/default_response.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ApiValidations/Response/default_response.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/ApiLayers/Schemas/identity/identity.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/Schemas/identity/identity.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/ApiLayers/ErrorHandlers/Exceptions/api_exc.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ErrorHandlers/Exceptions/api_exc.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/api_events.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/api_events.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/DockerApiServices/AuthServiceApi/create_routes.py" beforeDir="false" afterPath="$PROJECT_DIR$/DockerApiServices/AuthServiceApi/create_routes.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/auth.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/auth.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/auth.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/auth.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/models.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/function_handlers.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/function_handlers.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Services/PostgresDb/Models/crud_alchemy.py" beforeDir="false" afterPath="$PROJECT_DIR$/Services/PostgresDb/Models/crud_alchemy.py" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/Services/PostgresDb/Models/filter_functions.py" beforeDir="false" afterPath="$PROJECT_DIR$/Services/PostgresDb/Models/filter_functions.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/Services/PostgresDb/Models/filter_functions.py" beforeDir="false" afterPath="$PROJECT_DIR$/Services/PostgresDb/Models/filter_functions.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/Services/PostgresDb/Models/mixin.py" beforeDir="false" afterPath="$PROJECT_DIR$/Services/PostgresDb/Models/mixin.py" afterDir="false" />
|
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Python Script" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,16 @@ class WagRedis:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# VALIDATION_USER: str = "VALIDATION_USER"
|
||||||
|
class RedisValidationKeys:
|
||||||
|
ENDPOINTS: str = "ENDPOINTS"
|
||||||
|
VALIDATIONS: str = "VALIDATIONS"
|
||||||
|
HEADERS: str = "HEADERS"
|
||||||
|
ERRORCODES: str = "ERRORCODES"
|
||||||
|
RESPONSES: str = "RESPONSES"
|
||||||
|
LANGUAGE_MODELS: str = "LANGUAGE_MODELS"
|
||||||
|
|
||||||
|
|
||||||
class RedisAuthKeys:
|
class RedisAuthKeys:
|
||||||
AUTH: str = "AUTH"
|
AUTH: str = "AUTH"
|
||||||
OCCUPANT: str = "OCCUPANT"
|
OCCUPANT: str = "OCCUPANT"
|
||||||
|
|
@ -26,8 +36,6 @@ class RedisAuthKeys:
|
||||||
class RedisCategoryKeys:
|
class RedisCategoryKeys:
|
||||||
REBUILD: str = "REBUILD"
|
REBUILD: str = "REBUILD"
|
||||||
ENDPOINT2CLASS: str = "ENDPOINT2CLASS"
|
ENDPOINT2CLASS: str = "ENDPOINT2CLASS"
|
||||||
LANGUAGE_MODELS: str = "LANGUAGE_MODELS"
|
|
||||||
VALIDATION_USER: str = "VALIDATION_USER"
|
|
||||||
CLUSTER_INDEX: str = "CLUSTER_INDEX"
|
CLUSTER_INDEX: str = "CLUSTER_INDEX"
|
||||||
CLUSTER_FUNCTION_CODES: str = "CLUSTER_FUNCTION_CODES"
|
CLUSTER_FUNCTION_CODES: str = "CLUSTER_FUNCTION_CODES"
|
||||||
METHOD_FUNCTION_CODES: str = "METHOD_FUNCTION_CODES"
|
METHOD_FUNCTION_CODES: str = "METHOD_FUNCTION_CODES"
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ class UserLoginModule:
|
||||||
|
|
||||||
def __init__(self, request: "Request"):
|
def __init__(self, request: "Request"):
|
||||||
self.request = request
|
self.request = request
|
||||||
|
self.user = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def check_user_exists(access_key: str):
|
def check_user_exists(access_key: str):
|
||||||
|
|
@ -38,9 +39,9 @@ class UserLoginModule:
|
||||||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||||
from ApiLayers.Schemas import Users
|
from ApiLayers.Schemas import Users
|
||||||
|
|
||||||
"""Login user via credentials."""
|
|
||||||
# Get the actual data from the BaseRequestModel if needed
|
# Get the actual data from the BaseRequestModel if needed
|
||||||
found_user: Users = self.check_user_exists(access_key=access_data.access_key)
|
found_user: Users = self.check_user_exists(access_key=access_data.access_key)
|
||||||
|
self.user = found_user
|
||||||
if len(found_user.hash_password) < 5:
|
if len(found_user.hash_password) < 5:
|
||||||
raise HTTPExceptionApi(
|
raise HTTPExceptionApi(
|
||||||
error_code="HTTP_400_BAD_REQUEST",
|
error_code="HTTP_400_BAD_REQUEST",
|
||||||
|
|
|
||||||
|
|
@ -1,153 +1,118 @@
|
||||||
from ast import Dict
|
from typing import Optional
|
||||||
from typing import Any, Optional
|
|
||||||
from fastapi import status
|
from fastapi import status
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
|
|
||||||
class BaseEndpointResponse:
|
class BaseEndpointResponse:
|
||||||
|
|
||||||
def __init__(self, code: str, lang: str):
|
def __init__(self, lang: str, code: str):
|
||||||
self.code = code
|
|
||||||
self.lang = lang
|
self.lang = lang
|
||||||
|
self.code = code
|
||||||
|
|
||||||
def retrieve_message(self):
|
@property
|
||||||
messages = {}
|
def response(self) -> Optional[dict]:
|
||||||
return messages[self.code][self.lang]
|
from Services.Redis import RedisActions
|
||||||
|
from ApiLayers.AllConfigs.Redis.configs import RedisValidationKeys
|
||||||
|
|
||||||
|
language_model_key = f"{RedisValidationKeys.LANGUAGE_MODELS}:{RedisValidationKeys.RESPONSES}"
|
||||||
|
language_model = RedisActions.get_json(list_keys=[language_model_key, self.code , self.lang])
|
||||||
|
if language_model.status:
|
||||||
|
return language_model.first.as_dict
|
||||||
|
raise ValueError("Language model not found")
|
||||||
|
|
||||||
|
|
||||||
# 1. 200 OK
|
class EndpointSuccessResponse(BaseEndpointResponse): # 1. 200 OK
|
||||||
class EndpointSuccessResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
def as_dict(self, data: Optional[dict] = None):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_200_OK,
|
status_code=status.HTTP_200_OK,
|
||||||
content=dict(
|
content=dict(completed=True, lang=self.lang, data=data, **self.response)
|
||||||
completed=True,
|
|
||||||
message=self.retrieve_message(),
|
|
||||||
lang=self.lang,
|
|
||||||
data=data,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 2. 201 Created
|
class EndpointCreatedResponse(BaseEndpointResponse): # 2. 201 Created
|
||||||
class EndpointCreatedResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
def as_dict(self, data: Optional[dict] = None):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_201_CREATED,
|
status_code=status.HTTP_201_CREATED,
|
||||||
content=dict(
|
content=dict(completed=True, lang=self.lang, data=data, **self.response)
|
||||||
completed=True,
|
|
||||||
message=self.retrieve_message(),
|
|
||||||
lang=self.lang,
|
|
||||||
data=data,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 3. 202 Accepted
|
class EndpointAcceptedResponse(BaseEndpointResponse): # 3. 202 Accepted
|
||||||
class EndpointAcceptedResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
def as_dict(self, data: Optional[dict] = None):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_202_ACCEPTED,
|
status_code=status.HTTP_202_ACCEPTED,
|
||||||
content=dict(
|
content=dict(completed=True, lang=self.lang, data=data, **self.response)
|
||||||
completed=True,
|
|
||||||
message=self.retrieve_message(),
|
|
||||||
lang=self.lang,
|
|
||||||
data=data,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 4. 400 Bad Request
|
class EndpointBadRequestResponse(BaseEndpointResponse): # 4. 400 Bad Request
|
||||||
class EndpointBadRequestResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
def as_dict(self, data: Optional[dict] = None):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, data=data, **self.response)
|
||||||
completed=False,
|
|
||||||
message=self.retrieve_message(),
|
|
||||||
lang=self.lang,
|
|
||||||
data=data,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 5. 401 Unauthorized
|
class EndpointUnauthorizedResponse(BaseEndpointResponse): # 5. 401 Unauthorized
|
||||||
class EndpointUnauthorizedResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 6. 404 Not Found
|
class EndpointNotFoundResponse(BaseEndpointResponse): # 6. 404 Not Found
|
||||||
class EndpointNotFoundResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 3. 403 Forbidden
|
class EndpointForbiddenResponse(BaseEndpointResponse): # 3. 403 Forbidden
|
||||||
class EndpointForbiddenResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 6. 409 Conflict
|
class EndpointConflictResponse(BaseEndpointResponse): # 6. 409 Conflict
|
||||||
class EndpointConflictResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_409_CONFLICT,
|
status_code=status.HTTP_409_CONFLICT,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 7. 429 Too Many Requests
|
class EndpointTooManyRequestsResponse(BaseEndpointResponse): # 7. 429 Too Many Requests
|
||||||
class EndpointTooManyRequestsResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def __init__(self, retry_after: int):
|
def __init__(self, retry_after: int, lang: str, code: str):
|
||||||
|
super().__init__(lang=lang, code=code)
|
||||||
self.retry_after = retry_after
|
self.retry_after = retry_after
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
|
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
|
||||||
headers={"Retry-After": str(self.retry_after)},
|
headers={"Retry-After": str(self.retry_after)},
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# 7. 500 Internal Server Error
|
class EndpointInternalErrorResponse(BaseEndpointResponse): # 7. 500 Internal Server Error
|
||||||
class EndpointInternalErrorResponse(BaseEndpointResponse):
|
|
||||||
|
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -156,7 +121,5 @@ class EndpointErrorResponse(BaseEndpointResponse):
|
||||||
def as_dict(self):
|
def as_dict(self):
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
status_code=status.HTTP_304_NOT_MODIFIED,
|
status_code=status.HTTP_304_NOT_MODIFIED,
|
||||||
content=dict(
|
content=dict(completed=False, lang=self.lang, **self.response)
|
||||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
from Services.Redis.Actions.actions import RedisActions
|
||||||
|
|
||||||
|
|
||||||
class HTTPExceptionApi(Exception):
|
class HTTPExceptionApi(Exception):
|
||||||
|
|
||||||
def __init__(self, error_code: str, lang: str, loc: str = "", sys_msg: str = ""):
|
def __init__(self, error_code: str, lang: str, loc: str = "", sys_msg: str = ""):
|
||||||
|
|
@ -5,3 +8,11 @@ class HTTPExceptionApi(Exception):
|
||||||
self.lang = lang
|
self.lang = lang
|
||||||
self.loc = loc
|
self.loc = loc
|
||||||
self.sys_msg = sys_msg
|
self.sys_msg = sys_msg
|
||||||
|
|
||||||
|
def retrieve_error_message_by_code_at_redis(self):
|
||||||
|
"""
|
||||||
|
Retrieve the error message from the redis by the error code.
|
||||||
|
"""
|
||||||
|
error_msg = RedisActions.get_json(list_keys=["LANGUAGE_MODELS", "ERRORCODES", self.lang])
|
||||||
|
if error_msg.status:
|
||||||
|
return error_msg.first
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,23 @@
|
||||||
Route configuration and factory module.
|
Route configuration and factory module.
|
||||||
Handles dynamic route creation based on configurations.
|
Handles dynamic route creation based on configurations.
|
||||||
"""
|
"""
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
from fastapi import Request
|
|
||||||
from Events.Engine.set_defaults.run import get_cluster_controller_group
|
from Events.Engine.set_defaults.run import get_cluster_controller_group
|
||||||
from Events.Engine.set_defaults.setClusters import PrepareRouting, SetItems2Redis, PrepareEvents
|
from Events.Engine.set_defaults.setClusters import PrepareRouting, SetItems2Redis, PrepareEvents
|
||||||
|
|
||||||
routers = None
|
|
||||||
|
routers: Optional[PrepareRouting] = None
|
||||||
|
|
||||||
|
|
||||||
async def health_check(request: Request):
|
# async def health_check(request: Request):
|
||||||
"""Default health check endpoint."""
|
# """Default health check endpoint."""
|
||||||
return {"status": "healthy", "message": "Service is running"}
|
# return {"status": "healthy", "message": "Service is running"}
|
||||||
|
#
|
||||||
|
#
|
||||||
async def ping_test(request: Request, service_name: str = "base-router"):
|
# async def ping_test(request: Request, service_name: str = "base-router"):
|
||||||
"""Default ping test endpoint."""
|
# """Default ping test endpoint."""
|
||||||
return {"ping": "pong", "service": service_name}
|
# return {"ping": "pong", "service": service_name}
|
||||||
|
|
||||||
|
|
||||||
def get_all_routers() -> PrepareRouting:
|
def get_all_routers() -> PrepareRouting:
|
||||||
|
|
@ -27,11 +28,11 @@ def get_all_routers() -> PrepareRouting:
|
||||||
Returns:
|
Returns:
|
||||||
tuple: (routers, protected_routes)
|
tuple: (routers, protected_routes)
|
||||||
"""
|
"""
|
||||||
global routers
|
if routers:
|
||||||
if not routers:
|
return routers
|
||||||
|
|
||||||
cluster_list = get_cluster_controller_group()
|
cluster_list = get_cluster_controller_group()
|
||||||
prepare_routing = PrepareRouting(cluster_controller_group=cluster_list)
|
prepare_routing = PrepareRouting(cluster_controller_group=cluster_list)
|
||||||
prepare_events = PrepareEvents(cluster_controller_group=cluster_list)
|
prepare_events = PrepareEvents(cluster_controller_group=cluster_list)
|
||||||
set_items_2_redis = SetItems2Redis(prepare_events=prepare_events)
|
SetItems2Redis(prepare_events=prepare_events)
|
||||||
return prepare_routing
|
return prepare_routing
|
||||||
return routers
|
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ AuthenticationLoginEventMethods = MethodToEvent(
|
||||||
description="Login to the system via domain, access key : [email] | [phone]",
|
description="Login to the system via domain, access key : [email] | [phone]",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def authentication_login_with_domain_and_creds_endpoint(
|
def authentication_login_with_domain_and_creds_endpoint(
|
||||||
request: Request,
|
request: Request,
|
||||||
data: EndpointBaseRequestModel,
|
data: EndpointBaseRequestModel,
|
||||||
|
|
@ -78,11 +79,12 @@ def authentication_select_company_or_occupant_type(
|
||||||
"""
|
"""
|
||||||
Select company or occupant type.
|
Select company or occupant type.
|
||||||
"""
|
"""
|
||||||
auth_dict = authentication_select_company_or_occupant_type.auth
|
auth_context = authentication_select_company_or_occupant_type.auth_context
|
||||||
function = AuthenticationSelectEventMethods.retrieve_event(
|
function = AuthenticationSelectEventMethods.retrieve_event(
|
||||||
event_function_code=f"{authentication_select_company_or_occupant_type_super_user_event.key}"
|
event_function_code=f"{authentication_select_company_or_occupant_type_super_user_event.key}"
|
||||||
)
|
)
|
||||||
return function.endpoint_callable(request=request, data=data, token_dict=auth_dict)
|
function.endpoint_callable.auth_context = auth_context
|
||||||
|
return function.endpoint_callable(request=request, data=data)
|
||||||
|
|
||||||
|
|
||||||
AuthenticationSelectEventMethods.endpoint_callable = authentication_select_company_or_occupant_type
|
AuthenticationSelectEventMethods.endpoint_callable = authentication_select_company_or_occupant_type
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ from ApiLayers.Schemas import (
|
||||||
OccupantTypes,
|
OccupantTypes,
|
||||||
Users,
|
Users,
|
||||||
)
|
)
|
||||||
|
from ApiLayers.ApiValidations.Response.default_response import EndpointSuccessResponse
|
||||||
from fastapi import Request
|
from fastapi import Request
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -50,17 +51,28 @@ def authentication_login_with_domain_and_creds(request: Request, data: Any):
|
||||||
token = user_login_module.login_user_via_credentials(access_data=data)
|
token = user_login_module.login_user_via_credentials(access_data=data)
|
||||||
|
|
||||||
# Return response with token and headers
|
# Return response with token and headers
|
||||||
return {
|
user_login_module.language = "tr"
|
||||||
"completed": True,
|
success_response = EndpointSuccessResponse(
|
||||||
"message": "User is logged in successfully",
|
code="LoginSuccess", lang=user_login_module.language
|
||||||
|
)
|
||||||
|
return success_response.as_dict(
|
||||||
|
data={
|
||||||
"access_token": token.get("access_token"),
|
"access_token": token.get("access_token"),
|
||||||
"refresh_token": token.get("refresher_token"),
|
"refresh_token": token.get("refresher_token"),
|
||||||
"access_object": {
|
"access_object": {"user_type": token.get("user_type"), "companies_list": token.get("companies_list")},
|
||||||
"user_type": token.get("user_type"),
|
|
||||||
"companies_list": token.get("companies_list"),
|
|
||||||
},
|
|
||||||
"user": token.get("user"),
|
"user": token.get("user"),
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
# return {
|
||||||
|
# "completed": True,
|
||||||
|
# "message": "User is logged in successfully",
|
||||||
|
# "access_token": token.get("access_token"),
|
||||||
|
# "refresh_token": token.get("refresher_token"),
|
||||||
|
# "access_object": {
|
||||||
|
# "user_type": token.get("user_type"), "companies_list": token.get("companies_list")
|
||||||
|
# },
|
||||||
|
# "user": token.get("user"),
|
||||||
|
# }
|
||||||
|
|
||||||
|
|
||||||
def handle_employee_selection(request: Request, data: Any, token_dict: TokenDictType):
|
def handle_employee_selection(request: Request, data: Any, token_dict: TokenDictType):
|
||||||
|
|
@ -261,16 +273,15 @@ def handle_occupant_selection(request: Request, data: Any, token_dict: TokenDict
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def authentication_select_company_or_occupant_type(request: Request, data: Any, token_dict: TokenDictType):
|
def authentication_select_company_or_occupant_type(request: Request, data: Any):
|
||||||
"""Handle selection of company or occupant type"""
|
"""Handle selection of company or occupant type"""
|
||||||
|
token_dict: TokenDictType = authentication_select_company_or_occupant_type.auth_context
|
||||||
if token_dict.is_employee:
|
if token_dict.is_employee:
|
||||||
if handle_employee_selection(data, token_dict, request):
|
if handle_employee_selection(data, token_dict, request):
|
||||||
return {"selected_occupant": None, "selected_company": data.company_uu_id}
|
return {"selected_occupant": None, "selected_company": data.company_uu_id}
|
||||||
elif token_dict.is_occupant:
|
elif token_dict.is_occupant:
|
||||||
if handle_occupant_selection(data, token_dict, request):
|
if handle_occupant_selection(data, token_dict, request):
|
||||||
return {
|
return {"selected_company": None, "selected_occupant": data.build_living_space_uu_id}
|
||||||
"selected_company": None, "selected_occupant": data.build_living_space_uu_id,
|
|
||||||
}
|
|
||||||
return {"completed": False, "selected_company": None, "selected_occupant": None}
|
return {"completed": False, "selected_company": None, "selected_occupant": None}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ including pagination, ordering, and complex query building.
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import Any, TypeVar, Type
|
from typing import Any, TypeVar, Type
|
||||||
|
|
||||||
from sqlalchemy.orm import Query, Session
|
from sqlalchemy.orm import Query, Session
|
||||||
from sqlalchemy.sql.elements import BinaryExpression
|
from sqlalchemy.sql.elements import BinaryExpression
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue