aiteamutils 0.2.38__py3-none-any.whl → 0.2.40__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aiteamutils/dependencies.py +37 -9
- aiteamutils/exceptions.py +2 -1
- aiteamutils/version.py +1 -1
- {aiteamutils-0.2.38.dist-info → aiteamutils-0.2.40.dist-info}/METADATA +1 -1
- {aiteamutils-0.2.38.dist-info → aiteamutils-0.2.40.dist-info}/RECORD +6 -6
- {aiteamutils-0.2.38.dist-info → aiteamutils-0.2.40.dist-info}/WHEEL +0 -0
aiteamutils/dependencies.py
CHANGED
@@ -3,6 +3,7 @@ from fastapi import Depends, status
|
|
3
3
|
from fastapi.security import OAuth2PasswordBearer
|
4
4
|
from jose import JWTError, jwt
|
5
5
|
from sqlalchemy.ext.asyncio import AsyncSession
|
6
|
+
import logging
|
6
7
|
|
7
8
|
from .database import DatabaseService, get_database_service, get_db
|
8
9
|
from .exceptions import CustomException, ErrorCode
|
@@ -12,10 +13,12 @@ class ServiceRegistry:
|
|
12
13
|
"""서비스 레지스트리를 관리하는 클래스"""
|
13
14
|
def __init__(self):
|
14
15
|
self._services: Dict[str, Tuple[Type, Type]] = {}
|
16
|
+
self._initialized = False
|
15
17
|
|
16
18
|
def clear(self):
|
17
19
|
"""등록된 모든 서비스를 초기화합니다."""
|
18
20
|
self._services.clear()
|
21
|
+
self._initialized = False
|
19
22
|
|
20
23
|
def register(self, name: str, repository_class: Type, service_class: Type):
|
21
24
|
"""서비스를 레지스트리에 등록
|
@@ -28,13 +31,28 @@ class ServiceRegistry:
|
|
28
31
|
Raises:
|
29
32
|
CustomException: 이미 등록된 서비스인 경우
|
30
33
|
"""
|
31
|
-
|
34
|
+
try:
|
35
|
+
if name in self._services:
|
36
|
+
logging.warning(f"Service '{name}' is already registered. Skipping...")
|
37
|
+
return
|
38
|
+
|
39
|
+
if not repository_class or not service_class:
|
40
|
+
raise CustomException(
|
41
|
+
ErrorCode.INTERNAL_ERROR,
|
42
|
+
detail=f"Invalid service classes for '{name}'",
|
43
|
+
source_function="ServiceRegistry.register"
|
44
|
+
)
|
45
|
+
|
46
|
+
self._services[name] = (repository_class, service_class)
|
47
|
+
logging.info(f"Service '{name}' registered successfully")
|
48
|
+
|
49
|
+
except Exception as e:
|
32
50
|
raise CustomException(
|
33
51
|
ErrorCode.INTERNAL_ERROR,
|
34
|
-
detail=f"service
|
35
|
-
source_function="ServiceRegistry.register"
|
52
|
+
detail=f"Failed to register service '{name}': {str(e)}",
|
53
|
+
source_function="ServiceRegistry.register",
|
54
|
+
original_error=e
|
36
55
|
)
|
37
|
-
self._services[name] = (repository_class, service_class)
|
38
56
|
|
39
57
|
def get(self, name: str) -> Tuple[Type, Type]:
|
40
58
|
"""등록된 서비스를 조회
|
@@ -50,11 +68,19 @@ class ServiceRegistry:
|
|
50
68
|
"""
|
51
69
|
if name not in self._services:
|
52
70
|
raise CustomException(
|
53
|
-
ErrorCode.
|
54
|
-
detail=f"
|
71
|
+
ErrorCode.SERVICE_NOT_REGISTERED,
|
72
|
+
detail=f"Service '{name}' is not registered",
|
55
73
|
source_function="ServiceRegistry.get"
|
56
74
|
)
|
57
75
|
return self._services[name]
|
76
|
+
|
77
|
+
def is_initialized(self) -> bool:
|
78
|
+
"""서비스 레지스트리 초기화 여부를 반환합니다."""
|
79
|
+
return self._initialized
|
80
|
+
|
81
|
+
def set_initialized(self):
|
82
|
+
"""서비스 레지스트리를 초기화 상태로 설정합니다."""
|
83
|
+
self._initialized = True
|
58
84
|
|
59
85
|
# ServiceRegistry 초기화
|
60
86
|
service_registry = ServiceRegistry()
|
@@ -75,11 +101,13 @@ def get_service(name: str):
|
|
75
101
|
try:
|
76
102
|
repository_class, service_class = service_registry.get(name)
|
77
103
|
repository = repository_class(db_service)
|
78
|
-
return service_class(repository)
|
104
|
+
return service_class(repository, db_service)
|
105
|
+
except CustomException as e:
|
106
|
+
raise e
|
79
107
|
except Exception as e:
|
80
108
|
raise CustomException(
|
81
|
-
ErrorCode.
|
82
|
-
detail=f"Failed to create service {name}: {str(e)}",
|
109
|
+
ErrorCode.INTERNAL_ERROR,
|
110
|
+
detail=f"Failed to create service '{name}': {str(e)}",
|
83
111
|
source_function="dependencies.get_service",
|
84
112
|
original_error=e
|
85
113
|
)
|
aiteamutils/exceptions.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"""예외 처리 모듈."""
|
2
2
|
import logging
|
3
|
-
from enum import Enum
|
3
|
+
from enum import Enum, IntEnum
|
4
4
|
from typing import Dict, Any, Optional, Tuple, List
|
5
5
|
from fastapi import Request
|
6
6
|
from fastapi.responses import JSONResponse
|
@@ -69,6 +69,7 @@ class ErrorCode(Enum):
|
|
69
69
|
NOT_FOUND = ErrorResponse(5001, "GENERAL_NOT_FOUND", 404, "리소스를 찾을 수 없습니다")
|
70
70
|
INTERNAL_ERROR = ErrorResponse(5002, "GENERAL_INTERNAL_ERROR", 500, "내부 서버 오류")
|
71
71
|
SERVICE_UNAVAILABLE = ErrorResponse(5003, "GENERAL_SERVICE_UNAVAILABLE", 503, "서비스를 사용할 수 없습니다")
|
72
|
+
SERVICE_NOT_REGISTERED = ErrorResponse(5003, "GENERAL_SERVICE_UNAVAILABLE", 503, "서비스를 사용할 수 없습니다")
|
72
73
|
|
73
74
|
class CustomException(Exception):
|
74
75
|
"""사용자 정의 예외 클래스"""
|
aiteamutils/version.py
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
"""버전 정보"""
|
2
|
-
__version__ = "0.2.
|
2
|
+
__version__ = "0.2.40"
|
@@ -5,12 +5,12 @@ aiteamutils/base_service.py,sha256=E4dHGE0DvhmRyFplh46SwKJOSF_nUL7OAsCkf_ZJF_8,2
|
|
5
5
|
aiteamutils/cache.py,sha256=tr0Yn8VPYA9QHiKCUzciVlQ2J1RAwNo2K9lGMH4rY3s,1334
|
6
6
|
aiteamutils/config.py,sha256=kFKMeIx1KcuEwwx4VjZdCgoTOHCkG3ySYVJ0G6cvMoA,2849
|
7
7
|
aiteamutils/database.py,sha256=ATFiwG_o6o1eeUa0VVQ_2E_ExC2Yg-Ui_eA62SL6vQk,35344
|
8
|
-
aiteamutils/dependencies.py,sha256=
|
8
|
+
aiteamutils/dependencies.py,sha256=hsJ-kc8ic4U6vKFtUIWjhBE1_Bm-sya5UqSb2zMH5oM,5731
|
9
9
|
aiteamutils/enums.py,sha256=ipZi6k_QD5-3QV7Yzv7bnL0MjDz-vqfO9I5L77biMKs,632
|
10
|
-
aiteamutils/exceptions.py,sha256=
|
10
|
+
aiteamutils/exceptions.py,sha256=_lKWXq_ujNj41xN6LDE149PwsecAP7lgYWbOBbLOntg,15368
|
11
11
|
aiteamutils/security.py,sha256=9gvEqDtE3RJaoCWqELPCjkg-IsSqZVrpMP6XPZaodWU,16024
|
12
12
|
aiteamutils/validators.py,sha256=3N245cZFjgwtW_KzjESkizx5BBUDaJLbbxfNO4WOFZ0,7764
|
13
|
-
aiteamutils/version.py,sha256=
|
14
|
-
aiteamutils-0.2.
|
15
|
-
aiteamutils-0.2.
|
16
|
-
aiteamutils-0.2.
|
13
|
+
aiteamutils/version.py,sha256=r4koaMfodnLfd4IMWK3LkRqImEOtPrTfnvj9iHsKNak,42
|
14
|
+
aiteamutils-0.2.40.dist-info/METADATA,sha256=6EErFhk04VSuc_BO7JcenZSYnZYnp-gAJ82eVqFLiFg,1718
|
15
|
+
aiteamutils-0.2.40.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
aiteamutils-0.2.40.dist-info/RECORD,,
|
File without changes
|