language models updated
This commit is contained in:
parent
bc300f727a
commit
e403993d24
|
|
@ -5,23 +5,28 @@
|
|||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<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$/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/Token/token_handler.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ApiServices/Token/token_handler.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$/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$/ApiLayers/ApiValidations/Response/default_response.py" beforeDir="false" afterPath="$PROJECT_DIR$/ApiLayers/ApiValidations/Response/default_response.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$/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/models.py" beforeDir="false" afterPath="$PROJECT_DIR$/Events/AllEvents/authentication/auth/models.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$/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/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>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||
</component>
|
||||
<component name="FileTemplateManagerImpl">
|
||||
<option name="RECENT_TEMPLATES">
|
||||
<list>
|
||||
<option value="Python Script" />
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</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:
|
||||
AUTH: str = "AUTH"
|
||||
OCCUPANT: str = "OCCUPANT"
|
||||
|
|
@ -26,8 +36,6 @@ class RedisAuthKeys:
|
|||
class RedisCategoryKeys:
|
||||
REBUILD: str = "REBUILD"
|
||||
ENDPOINT2CLASS: str = "ENDPOINT2CLASS"
|
||||
LANGUAGE_MODELS: str = "LANGUAGE_MODELS"
|
||||
VALIDATION_USER: str = "VALIDATION_USER"
|
||||
CLUSTER_INDEX: str = "CLUSTER_INDEX"
|
||||
CLUSTER_FUNCTION_CODES: str = "CLUSTER_FUNCTION_CODES"
|
||||
METHOD_FUNCTION_CODES: str = "METHOD_FUNCTION_CODES"
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ class UserLoginModule:
|
|||
|
||||
def __init__(self, request: "Request"):
|
||||
self.request = request
|
||||
self.user = None
|
||||
|
||||
@staticmethod
|
||||
def check_user_exists(access_key: str):
|
||||
|
|
@ -38,9 +39,9 @@ class UserLoginModule:
|
|||
from ApiLayers.ApiServices.Token.token_handler import TokenService
|
||||
from ApiLayers.Schemas import Users
|
||||
|
||||
"""Login user via credentials."""
|
||||
# Get the actual data from the BaseRequestModel if needed
|
||||
found_user: Users = self.check_user_exists(access_key=access_data.access_key)
|
||||
self.user = found_user
|
||||
if len(found_user.hash_password) < 5:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
|
|
|
|||
|
|
@ -1,153 +1,118 @@
|
|||
from ast import Dict
|
||||
from typing import Any, Optional
|
||||
from typing import Optional
|
||||
from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
|
||||
class BaseEndpointResponse:
|
||||
|
||||
def __init__(self, code: str, lang: str):
|
||||
self.code = code
|
||||
def __init__(self, lang: str, code: str):
|
||||
self.lang = lang
|
||||
self.code = code
|
||||
|
||||
def retrieve_message(self):
|
||||
messages = {}
|
||||
return messages[self.code][self.lang]
|
||||
@property
|
||||
def response(self) -> Optional[dict]:
|
||||
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):
|
||||
class EndpointSuccessResponse(BaseEndpointResponse): # 1. 200 OK
|
||||
|
||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
||||
def as_dict(self, data: Optional[dict] = None):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_200_OK,
|
||||
content=dict(
|
||||
completed=True,
|
||||
message=self.retrieve_message(),
|
||||
lang=self.lang,
|
||||
data=data,
|
||||
),
|
||||
content=dict(completed=True, lang=self.lang, data=data, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 2. 201 Created
|
||||
class EndpointCreatedResponse(BaseEndpointResponse):
|
||||
class EndpointCreatedResponse(BaseEndpointResponse): # 2. 201 Created
|
||||
|
||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
||||
def as_dict(self, data: Optional[dict] = None):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
content=dict(
|
||||
completed=True,
|
||||
message=self.retrieve_message(),
|
||||
lang=self.lang,
|
||||
data=data,
|
||||
),
|
||||
content=dict(completed=True, lang=self.lang, data=data, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 3. 202 Accepted
|
||||
class EndpointAcceptedResponse(BaseEndpointResponse):
|
||||
class EndpointAcceptedResponse(BaseEndpointResponse): # 3. 202 Accepted
|
||||
|
||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
||||
def as_dict(self, data: Optional[dict] = None):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
content=dict(
|
||||
completed=True,
|
||||
message=self.retrieve_message(),
|
||||
lang=self.lang,
|
||||
data=data,
|
||||
),
|
||||
content=dict(completed=True, lang=self.lang, data=data, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 4. 400 Bad Request
|
||||
class EndpointBadRequestResponse(BaseEndpointResponse):
|
||||
class EndpointBadRequestResponse(BaseEndpointResponse): # 4. 400 Bad Request
|
||||
|
||||
def as_dict(self, data: Optional[Dict[str, Any]] = None):
|
||||
def as_dict(self, data: Optional[dict] = None):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
content=dict(
|
||||
completed=False,
|
||||
message=self.retrieve_message(),
|
||||
lang=self.lang,
|
||||
data=data,
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, data=data, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 5. 401 Unauthorized
|
||||
class EndpointUnauthorizedResponse(BaseEndpointResponse):
|
||||
class EndpointUnauthorizedResponse(BaseEndpointResponse): # 5. 401 Unauthorized
|
||||
|
||||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 6. 404 Not Found
|
||||
class EndpointNotFoundResponse(BaseEndpointResponse):
|
||||
class EndpointNotFoundResponse(BaseEndpointResponse): # 6. 404 Not Found
|
||||
|
||||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 3. 403 Forbidden
|
||||
class EndpointForbiddenResponse(BaseEndpointResponse):
|
||||
class EndpointForbiddenResponse(BaseEndpointResponse): # 3. 403 Forbidden
|
||||
|
||||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 6. 409 Conflict
|
||||
class EndpointConflictResponse(BaseEndpointResponse):
|
||||
class EndpointConflictResponse(BaseEndpointResponse): # 6. 409 Conflict
|
||||
|
||||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 7. 429 Too Many Requests
|
||||
class EndpointTooManyRequestsResponse(BaseEndpointResponse):
|
||||
class EndpointTooManyRequestsResponse(BaseEndpointResponse): # 7. 429 Too Many Requests
|
||||
|
||||
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
|
||||
|
||||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_429_TOO_MANY_REQUESTS,
|
||||
headers={"Retry-After": str(self.retry_after)},
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
||||
|
||||
# 7. 500 Internal Server Error
|
||||
class EndpointInternalErrorResponse(BaseEndpointResponse):
|
||||
class EndpointInternalErrorResponse(BaseEndpointResponse): # 7. 500 Internal Server Error
|
||||
|
||||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -156,7 +121,5 @@ class EndpointErrorResponse(BaseEndpointResponse):
|
|||
def as_dict(self):
|
||||
return JSONResponse(
|
||||
status_code=status.HTTP_304_NOT_MODIFIED,
|
||||
content=dict(
|
||||
completed=False, message=self.retrieve_message(), lang=self.lang
|
||||
),
|
||||
content=dict(completed=False, lang=self.lang, **self.response)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
from Services.Redis.Actions.actions import RedisActions
|
||||
|
||||
|
||||
class HTTPExceptionApi(Exception):
|
||||
|
||||
def __init__(self, error_code: str, lang: str, loc: str = "", sys_msg: str = ""):
|
||||
|
|
@ -5,3 +8,11 @@ class HTTPExceptionApi(Exception):
|
|||
self.lang = lang
|
||||
self.loc = loc
|
||||
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.
|
||||
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.setClusters import PrepareRouting, SetItems2Redis, PrepareEvents
|
||||
|
||||
routers = None
|
||||
|
||||
routers: Optional[PrepareRouting] = None
|
||||
|
||||
|
||||
async def health_check(request: Request):
|
||||
"""Default health check endpoint."""
|
||||
return {"status": "healthy", "message": "Service is running"}
|
||||
|
||||
|
||||
async def ping_test(request: Request, service_name: str = "base-router"):
|
||||
"""Default ping test endpoint."""
|
||||
return {"ping": "pong", "service": service_name}
|
||||
# async def health_check(request: Request):
|
||||
# """Default health check endpoint."""
|
||||
# return {"status": "healthy", "message": "Service is running"}
|
||||
#
|
||||
#
|
||||
# async def ping_test(request: Request, service_name: str = "base-router"):
|
||||
# """Default ping test endpoint."""
|
||||
# return {"ping": "pong", "service": service_name}
|
||||
|
||||
|
||||
def get_all_routers() -> PrepareRouting:
|
||||
|
|
@ -27,11 +28,11 @@ def get_all_routers() -> PrepareRouting:
|
|||
Returns:
|
||||
tuple: (routers, protected_routes)
|
||||
"""
|
||||
global routers
|
||||
if not routers:
|
||||
cluster_list = get_cluster_controller_group()
|
||||
prepare_routing = PrepareRouting(cluster_controller_group=cluster_list)
|
||||
prepare_events = PrepareEvents(cluster_controller_group=cluster_list)
|
||||
set_items_2_redis = SetItems2Redis(prepare_events=prepare_events)
|
||||
return prepare_routing
|
||||
return routers
|
||||
if routers:
|
||||
return routers
|
||||
|
||||
cluster_list = get_cluster_controller_group()
|
||||
prepare_routing = PrepareRouting(cluster_controller_group=cluster_list)
|
||||
prepare_events = PrepareEvents(cluster_controller_group=cluster_list)
|
||||
SetItems2Redis(prepare_events=prepare_events)
|
||||
return prepare_routing
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ AuthenticationLoginEventMethods = MethodToEvent(
|
|||
description="Login to the system via domain, access key : [email] | [phone]",
|
||||
)
|
||||
|
||||
|
||||
def authentication_login_with_domain_and_creds_endpoint(
|
||||
request: Request,
|
||||
data: EndpointBaseRequestModel,
|
||||
|
|
@ -78,11 +79,12 @@ def authentication_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(
|
||||
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
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ from ApiLayers.Schemas import (
|
|||
OccupantTypes,
|
||||
Users,
|
||||
)
|
||||
from ApiLayers.ApiValidations.Response.default_response import EndpointSuccessResponse
|
||||
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)
|
||||
|
||||
# Return response with token and headers
|
||||
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"),
|
||||
}
|
||||
user_login_module.language = "tr"
|
||||
success_response = EndpointSuccessResponse(
|
||||
code="LoginSuccess", lang=user_login_module.language
|
||||
)
|
||||
return success_response.as_dict(
|
||||
data={
|
||||
"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"),
|
||||
}
|
||||
)
|
||||
# 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):
|
||||
|
|
@ -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"""
|
||||
token_dict: TokenDictType = authentication_select_company_or_occupant_type.auth_context
|
||||
if token_dict.is_employee:
|
||||
if handle_employee_selection(data, token_dict, request):
|
||||
return {"selected_occupant": None, "selected_company": data.company_uu_id}
|
||||
elif token_dict.is_occupant:
|
||||
if handle_occupant_selection(data, token_dict, request):
|
||||
return {
|
||||
"selected_company": None, "selected_occupant": data.build_living_space_uu_id,
|
||||
}
|
||||
return {"selected_company": None, "selected_occupant": data.build_living_space_uu_id}
|
||||
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 typing import Any, TypeVar, Type
|
||||
|
||||
from sqlalchemy.orm import Query, Session
|
||||
from sqlalchemy.sql.elements import BinaryExpression
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue