update events via wrapper routers
This commit is contained in:
@@ -10,6 +10,7 @@ from fastapi import Request, status
|
||||
from fastapi.responses import JSONResponse
|
||||
from pymongo.errors import PyMongoError, DuplicateKeyError, ConnectionFailure
|
||||
|
||||
from ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from Services.MongoDb.Models.exceptions import (
|
||||
MongoBaseException,
|
||||
MongoConnectionError,
|
||||
@@ -54,6 +55,7 @@ def handle_mongo_errors(func: Callable) -> Callable:
|
||||
raise HTTPExceptionApi(
|
||||
lang="en",
|
||||
error_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
return wrapper
|
||||
|
||||
@@ -20,6 +20,7 @@ from pymongo.errors import (
|
||||
PyMongoError,
|
||||
)
|
||||
|
||||
from ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ErrorHandlers.ErrorHandlers.api_exc_handler import HTTPExceptionApi
|
||||
|
||||
|
||||
@@ -34,14 +35,28 @@ def handle_mongo_errors(func):
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
except ConnectionFailure:
|
||||
raise HTTPExceptionApi(error_code="HTTP_503_SERVICE_UNAVAILABLE", lang="en")
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_503_SERVICE_UNAVAILABLE",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
except ServerSelectionTimeoutError:
|
||||
raise HTTPExceptionApi(error_code="HTTP_504_GATEWAY_TIMEOUT", lang="en")
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_504_GATEWAY_TIMEOUT",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
except OperationFailure as e:
|
||||
raise HTTPExceptionApi(error_code="HTTP_400_BAD_REQUEST", lang="en")
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
except PyMongoError as e:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_500_INTERNAL_SERVER_ERROR", lang="en"
|
||||
error_code="HTTP_500_INTERNAL_SERVER_ERROR",
|
||||
lang="en",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
return wrapper
|
||||
|
||||
@@ -18,6 +18,7 @@ from dataclasses import dataclass
|
||||
from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from Services.PostgresDb.Models.response import PostgresResponse
|
||||
from ErrorHandlers.ErrorHandlers.api_exc_handler import HTTPExceptionApi
|
||||
from Services.pagination import Pagination, PaginationConfig
|
||||
@@ -159,6 +160,7 @@ class BaseJsonResponse(Generic[T]):
|
||||
raise HTTPExceptionApi(
|
||||
lang=cls_object.lang,
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
|
||||
@@ -198,6 +200,7 @@ class SinglePostgresResponse(BaseJsonResponse[T]):
|
||||
raise HTTPExceptionApi(
|
||||
lang=cls_object.lang,
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
instance = super().__new__(cls)
|
||||
@@ -253,6 +256,7 @@ class AlchemyJsonResponse(BaseJsonResponse[T]):
|
||||
raise HTTPExceptionApi(
|
||||
lang=cls_object.lang,
|
||||
error_code="HTTP_400_BAD_REQUEST",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
instance = super().__new__(cls)
|
||||
|
||||
@@ -16,6 +16,7 @@ from sqlalchemy.orm import Query, Session
|
||||
from sqlalchemy.sql.elements import BinaryExpression
|
||||
|
||||
from ApiLibrary import system_arrow
|
||||
from ApiLibrary.common.line_number import get_line_number_for_error
|
||||
from ErrorHandlers.Exceptions.api_exc import HTTPExceptionApi
|
||||
from Services.PostgresDb.Models.response import PostgresResponse
|
||||
|
||||
@@ -137,6 +138,7 @@ class FilterAttributes:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_304_NOT_MODIFIED",
|
||||
lang=cls.lang or "tr",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -170,6 +172,7 @@ class FilterAttributes:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_304_NOT_MODIFIED",
|
||||
lang=cls.lang or "tr",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -189,6 +192,7 @@ class FilterAttributes:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_304_NOT_MODIFIED",
|
||||
lang=cls.lang or "tr",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -220,6 +224,7 @@ class FilterAttributes:
|
||||
raise HTTPExceptionApi(
|
||||
error_code="HTTP_304_NOT_MODIFIED",
|
||||
lang=cls.lang or "tr",
|
||||
loc=get_line_number_for_error(),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -522,5 +527,5 @@ class FilterAttributes:
|
||||
# """
|
||||
# raise HTTPExceptionApi(
|
||||
# error_code="HTTP_304_NOT_MODIFIED",
|
||||
# lang=cls.lang or "tr",
|
||||
# lang=cls.lang or "tr", loc=get_line_number_for_error()
|
||||
# )
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import json
|
||||
import arrow
|
||||
|
||||
from typing import Optional, List, Dict, Union
|
||||
@@ -20,6 +21,43 @@ class RedisActions:
|
||||
for unit, multiplier in time_multipliers.items()
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def delete_key(cls, key: Union[Optional[str], Optional[bytes]]):
|
||||
try:
|
||||
redis_cli.delete(key)
|
||||
return RedisResponse(
|
||||
status=True,
|
||||
message="Value is deleted successfully.",
|
||||
)
|
||||
except Exception as e:
|
||||
return RedisResponse(
|
||||
status=False,
|
||||
message="Value is not deleted successfully.",
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def delete(
|
||||
cls, list_keys: List[Union[Optional[str], Optional[bytes]]]
|
||||
) -> RedisResponse:
|
||||
try:
|
||||
regex = RedisRow.regex(list_keys=list_keys)
|
||||
json_get = redis_cli.scan_iter(match=regex)
|
||||
|
||||
for row in list(json_get):
|
||||
redis_cli.delete(row)
|
||||
|
||||
return RedisResponse(
|
||||
status=True,
|
||||
message="Values are deleted successfully.",
|
||||
)
|
||||
except Exception as e:
|
||||
return RedisResponse(
|
||||
status=False,
|
||||
message="Values are not deleted successfully.",
|
||||
error=str(e),
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_json(
|
||||
cls,
|
||||
|
||||
@@ -131,7 +131,7 @@ class RedisRow:
|
||||
return key_str.split(cls.delimiter)
|
||||
|
||||
@classmethod
|
||||
def feed(cls, value: Union[bytes, Dict, List]) -> None:
|
||||
def feed(cls, value: Union[bytes, Dict, List, str]) -> None:
|
||||
"""
|
||||
Convert and store value in JSON format.
|
||||
|
||||
@@ -151,6 +151,8 @@ class RedisRow:
|
||||
cls.value = json.dumps(value)
|
||||
elif isinstance(value, bytes):
|
||||
cls.value = json.dumps(json.loads(value.decode()))
|
||||
elif isinstance(value, str):
|
||||
cls.value = value
|
||||
else:
|
||||
raise RedisValueError(f"Unsupported value type: {type(value)}")
|
||||
except json.JSONDecodeError as e:
|
||||
|
||||
@@ -1,12 +1,22 @@
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, validator
|
||||
|
||||
|
||||
class AccessToken(BaseModel):
|
||||
|
||||
accessToken: str
|
||||
userUUID: str
|
||||
accessToken: Optional[str] = None
|
||||
userUUID: Optional[str] = None
|
||||
|
||||
@validator("userUUID", pre=True)
|
||||
def validate_uuid(cls, v):
|
||||
"""Convert UUID to string during validation."""
|
||||
if isinstance(v, UUID):
|
||||
return str(v)
|
||||
return v
|
||||
|
||||
def to_list(self):
|
||||
"""Convert to list for Redis storage."""
|
||||
return [self.accessToken, self.userUUID]
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user